renuo-cli 1.4.0 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d06bce9aa4b4a3585383e216d0ec8a40934c744c0ef744ef6c5b93662bc48b7c
4
- data.tar.gz: 38a4a1b6d6bdcf1e752b6e06ef35bde896f4369a51e7d6e1094b581d7e876445
3
+ metadata.gz: 0f06e6488ea32de05ac9691ab1015a655d4367f2f68a52ba48a2038a325f4305
4
+ data.tar.gz: 9960b0b755b7291ee5f32ed0ee896f4e91872772b025c6436fa301f340c08da7
5
5
  SHA512:
6
- metadata.gz: 2287372eff3dd81ddb3c615b03aa8bc5509008b8e349450ac5c4bceb2ee5710456b5035f35e2f9fd5210cf81bf9c175240268610de422971d3c5f2a8a14eb6b9
7
- data.tar.gz: ccb4f801d47581ce421ef865410e55456774ac98e1f3252430ee3ad1750dbceabb71253590add5e48d4f589f6b6babf993d6c6dfec9f1659bdfe1b891327024f
6
+ metadata.gz: 9ac14e70db95c79f2a11c3480ed7549ea1890d7106c554c2e34b2f63d8e558774a95ffd920d9cba843c67a93ccc75ecb14ce66ce9febdb96c04b4ea738c35032
7
+ data.tar.gz: 86ea2087c39035f34b67f846a738d43f665fbd99b15b201993843c24d7561b64a4430f8ba4ee0ed935f81f0815bb26a0113a86939b37d719758557d765127311
@@ -13,6 +13,7 @@ require 'renuo/cli/app/create_new_logins'
13
13
  require 'renuo/cli/app/release_project.rb'
14
14
  require 'renuo/cli/app/fetch_emails.rb'
15
15
  require 'renuo/cli/app/heroku_users.rb'
16
+ require 'renuo/cli/app/setup_uptimerobot'
16
17
 
17
18
  module Renuo
18
19
  class CLI
@@ -168,6 +169,18 @@ module Renuo
168
169
  HerokuUsers.new.run(args)
169
170
  end
170
171
  end
172
+
173
+ command 'setup-uptimerobot' do |c|
174
+ c.syntax = 'renuo setup-uptimerobot'
175
+ c.summary = 'Sets up uptimerobot for the given project'
176
+ c.description = "The uptimerobot configuration is mandatory for most projects. "\
177
+ "This command sets everything up and pauses the monitoring directly. Once the app is ready,"\
178
+ " the monitoring should get started."
179
+ c.example 'renuo setup-uptimerobot https://redmine.ch', 'Configures redmine monitoring on uptimerobot'
180
+ c.action do|args|
181
+ SetupUptimerobot.new(args).run
182
+ end
183
+ end
171
184
  end
172
185
  end
173
186
  end
@@ -19,6 +19,7 @@ class CreateHerokuApp
19
19
  ENVIRONMENTS.each do |env|
20
20
  print_environment_commands(emails, env, project_name)
21
21
  end
22
+ print_pipelines_commands(project_name)
22
23
  end
23
24
 
24
25
  private
@@ -32,11 +33,9 @@ class CreateHerokuApp
32
33
  say "heroku labs:enable runtime-dyno-metadata --app #{heroku_name}"
33
34
  say "heroku pg:backups:schedule DATABASE_URL --at '02:00 Europe/Zurich' --app #{heroku_name}"
34
35
  print_ownership_commands(emails, heroku_name)
35
- print_pipelines_commands(heroku_name, project_name)
36
36
  end
37
37
 
38
- def print_pipelines_commands(heroku_name, project_name)
39
- say "heroku apps:transfer -a #{heroku_name} #{ADMIN_EMAIL}"
38
+ def print_pipelines_commands(project_name)
40
39
  say "heroku pipelines:create #{project_name} --app #{project_name}-#{MASTER} -s production"
41
40
  say "heroku pipelines:add #{project_name} --app #{project_name}-#{DEVELOP} -s staging"
42
41
  say "heroku pipelines:add #{project_name} --app #{project_name}-#{TESTING} -s staging"
@@ -49,6 +48,7 @@ class CreateHerokuApp
49
48
  say "heroku access:add #{email} --app #{heroku_name}"
50
49
  end
51
50
  say "heroku access:add #{ADMIN_EMAIL} --app #{heroku_name}"
51
+ say "heroku apps:transfer -a #{heroku_name} #{ADMIN_EMAIL}"
52
52
  say "\n"
53
53
  end
54
54
  end
@@ -87,12 +87,12 @@ class ReleaseProject
87
87
 
88
88
  def current_version
89
89
  return @current_version if @current_version
90
- describe = cmd_in_folder('git describe --tags')
91
- tag = '`git rev-list --tags --max-count=1`'
90
+
92
91
  @current_version = if `#{cmd_in_folder('git tag')}` == ''
93
92
  '0.0.0'
94
93
  else
95
- `#{describe} #{tag}`.strip
94
+ sorted_tags = `git tag --sort=taggerdate`.split("\n").reverse
95
+ sorted_tags.find { |tag| tag =~ /\d+\.\d+\.\d+/ }.strip
96
96
  end
97
97
  end
98
98
 
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'net/http'
4
+ require 'json'
5
+
6
+ class SetupUptimerobot
7
+ CONTACT_GROUP_IDS = '2811620_0_0-2806053_0_0'
8
+ HTTPS_MONITORING = 1
9
+ STATUS_PAUSED = 0
10
+
11
+ def initialize(args)
12
+ abort('No project name given.') if args.nil?
13
+ @api_key = ask_for_api_key
14
+ @url = validate_url(args)
15
+ end
16
+
17
+ def run
18
+ robot_obj = monitoring_call(:new, create_robot_params)
19
+ validate_new_project(robot_obj)
20
+ response = monitoring_call(:edit, edit_robot_params(robot_obj['monitor']['id']))
21
+ final_command_status(response)
22
+ end
23
+
24
+ private
25
+
26
+ def ask_for_api_key
27
+ say 'This command will configure uptimerobot for your project.'
28
+ say 'Please give in the api_key for uptimerobot'
29
+ ask('API-key: ')
30
+ end
31
+
32
+ def validate_url(args)
33
+ abort('The url to be monitored was not given') if args.first.nil?
34
+ abort('The url is invalid') unless args.first =~ URI::DEFAULT_PARSER.make_regexp
35
+ URI.parse(args.first)
36
+ end
37
+
38
+ def create_robot_params
39
+ {
40
+ friendly_name: @url.host.downcase,
41
+ url: @url.to_s,
42
+ type: HTTPS_MONITORING,
43
+ interval: 300,
44
+ alert_contacts: CONTACT_GROUP_IDS
45
+ }
46
+ end
47
+
48
+ def edit_robot_params(uptimerobot_monitoring_id)
49
+ { id: uptimerobot_monitoring_id, status: STATUS_PAUSED }
50
+ end
51
+
52
+ def final_command_status(response)
53
+ if response['stat'] == 'ok'
54
+ say 'Successfully configured uptimerobot 🤩😎👍'
55
+ say 'The status for the monitored project has paused for now...'
56
+ say 'You can start it once your app is ready to go live 🤠'
57
+ else
58
+ say "Something went wrong during the configuration...😕. Uptimerobot returned '#{response['error']['message']}'"
59
+ end
60
+ end
61
+
62
+ def validate_new_project(robot_obj)
63
+ return if robot_obj['stat'] == 'ok'
64
+ abort("An error occoured. Uptimerobot returned '#{robot_obj['error']['message']}'")
65
+ end
66
+
67
+ def https_request(path, params = {})
68
+ uri = URI(path)
69
+ req = request_body(uri, params)
70
+ Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
71
+ http.request(req)
72
+ end
73
+ end
74
+
75
+ def request_body(uri, params)
76
+ params[:api_key] = @api_key
77
+ data = URI.encode_www_form params
78
+ req = Net::HTTP::Post.new(uri)
79
+ req.body = data
80
+ req
81
+ end
82
+
83
+ def monitoring_call(action, params)
84
+ response = https_request("https://api.uptimerobot.com/v2/#{action}Monitor", params)
85
+ JSON.parse(response.body)
86
+ end
87
+ end
@@ -1,6 +1,6 @@
1
1
  module Renuo
2
2
  module Cli
3
- VERSION = '1.4.0'.freeze
3
+ VERSION = '1.4.1'.freeze
4
4
  NAME = 'renuo-cli'.freeze
5
5
  end
6
6
  end
@@ -1,7 +1,7 @@
1
1
  lib = File.expand_path('lib', __dir__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
  require 'renuo/cli/version'
4
-
4
+ # rubocop:disable Metrics/BlockLength
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = Renuo::Cli::NAME
7
7
  spec.version = Renuo::Cli::VERSION
@@ -26,10 +26,14 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency 'bundler', '~> 2.0'
27
27
  spec.add_development_dependency 'coveralls', '~> 0.8.9'
28
28
  spec.add_development_dependency 'cucumber', '~> 3.1'
29
+ spec.add_development_dependency 'dotenv', '~> 2.7.2'
29
30
  spec.add_development_dependency 'mdl', '~> 0.4.0'
30
31
  spec.add_development_dependency 'pry', '~> 0.11.3'
31
32
  spec.add_development_dependency 'rake', '~> 10.0'
32
33
  spec.add_development_dependency 'rspec', '~> 3.5'
33
34
  spec.add_development_dependency 'rubocop', '0.55.0'
34
35
  spec.add_development_dependency 'simplecov', '0.10.0' # TODO: update and fix coverage
36
+ spec.add_development_dependency 'vcr', '~> 4.0.0'
37
+ spec.add_development_dependency 'webmock', '~> 3.5.1'
35
38
  end
39
+ # rubocop:enable Metrics/BlockLength
@@ -0,0 +1,93 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.uptimerobot.com/v2/newMonitor
6
+ body:
7
+ encoding: US-ASCII
8
+ string: friendly_name=test.ch&url=https%3A%2F%2Ftest.ch&type=1&interval=300&alert_contacts=0716852_0_0-2806074_0_0&api_key=<API-KEY>
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ Host:
17
+ - api.uptimerobot.com
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Date:
24
+ - Fri, 05 Apr 2019 15:04:18 GMT
25
+ Content-Type:
26
+ - application/json; charset=utf-8
27
+ Transfer-Encoding:
28
+ - chunked
29
+ Connection:
30
+ - keep-alive
31
+ Access-Control-Allow-Origin:
32
+ - "*"
33
+ Etag:
34
+ - W/"33-+Q4/l04ZnLs/j/WZc5awQaqxWko"
35
+ Vary:
36
+ - Accept-Encoding
37
+ Expect-Ct:
38
+ - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
39
+ Server:
40
+ - cloudflare
41
+ Cf-Ray:
42
+ - 4c2c69e72e76cc60-ZRH
43
+ body:
44
+ encoding: ASCII-8BIT
45
+ string: '{"stat":"ok","monitor":{"id":782356891,"status":1}}'
46
+ http_version:
47
+ recorded_at: Fri, 05 Apr 2019 15:04:18 GMT
48
+ - request:
49
+ method: post
50
+ uri: https://api.uptimerobot.com/v2/editMonitor
51
+ body:
52
+ encoding: US-ASCII
53
+ string: id=782356891&status=0&api_key=<API-KEY>
54
+ headers:
55
+ Accept-Encoding:
56
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
57
+ Accept:
58
+ - "*/*"
59
+ User-Agent:
60
+ - Ruby
61
+ Host:
62
+ - api.uptimerobot.com
63
+ response:
64
+ status:
65
+ code: 200
66
+ message: OK
67
+ headers:
68
+ Date:
69
+ - Fri, 05 Apr 2019 15:04:18 GMT
70
+ Content-Type:
71
+ - application/json; charset=utf-8
72
+ Content-Length:
73
+ - '40'
74
+ Connection:
75
+ - keep-alive
76
+ Access-Control-Allow-Origin:
77
+ - "*"
78
+ Etag:
79
+ - W/"28-IX6S7KrVjMYO09zUzWnglIFSrbs"
80
+ Vary:
81
+ - Accept-Encoding
82
+ Expect-Ct:
83
+ - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
84
+ Server:
85
+ - cloudflare
86
+ Cf-Ray:
87
+ - 4c2c69e8be39cc3c-ZRH
88
+ body:
89
+ encoding: UTF-8
90
+ string: '{"stat":"ok","monitor":{"id":782356891}}'
91
+ http_version:
92
+ recorded_at: Fri, 05 Apr 2019 15:04:18 GMT
93
+ recorded_with: VCR 4.0.0
@@ -0,0 +1,48 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.uptimerobot.com/v2/newMonitor
6
+ body:
7
+ encoding: US-ASCII
8
+ string: friendly_name=test.ch&url=https%3A%2F%2Ftest.ch&type=1&interval=300&alert_contacts=0716852_0_0-2806074_0_0&api_key=<API-KEY>
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ Host:
17
+ - api.uptimerobot.com
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Date:
24
+ - Fri, 05 Apr 2019 15:04:18 GMT
25
+ Content-Type:
26
+ - application/json; charset=utf-8
27
+ Transfer-Encoding:
28
+ - chunked
29
+ Connection:
30
+ - keep-alive
31
+ Access-Control-Allow-Origin:
32
+ - "*"
33
+ Etag:
34
+ - W/"55-MrMKN/ToW+ARHfUbinDrKAYK9Jc"
35
+ Vary:
36
+ - Accept-Encoding
37
+ Expect-Ct:
38
+ - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
39
+ Server:
40
+ - cloudflare
41
+ Cf-Ray:
42
+ - 4c2c69ea6f943e5c-ZRH
43
+ body:
44
+ encoding: ASCII-8BIT
45
+ string: '{"stat":"fail","error":{"type":"already_exists","message":"monitor already exists."}}'
46
+ http_version:
47
+ recorded_at: Fri, 05 Apr 2019 15:04:18 GMT
48
+ recorded_with: VCR 4.0.0
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: renuo-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Renuo AG
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-19 00:00:00.000000000 Z
11
+ date: 2019-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: '3.1'
125
+ - !ruby/object:Gem::Dependency
126
+ name: dotenv
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 2.7.2
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 2.7.2
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: mdl
127
141
  requirement: !ruby/object:Gem::Requirement
@@ -206,6 +220,34 @@ dependencies:
206
220
  - - '='
207
221
  - !ruby/object:Gem::Version
208
222
  version: 0.10.0
223
+ - !ruby/object:Gem::Dependency
224
+ name: vcr
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - "~>"
228
+ - !ruby/object:Gem::Version
229
+ version: 4.0.0
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - "~>"
235
+ - !ruby/object:Gem::Version
236
+ version: 4.0.0
237
+ - !ruby/object:Gem::Dependency
238
+ name: webmock
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - "~>"
242
+ - !ruby/object:Gem::Version
243
+ version: 3.5.1
244
+ type: :development
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - "~>"
249
+ - !ruby/object:Gem::Version
250
+ version: 3.5.1
209
251
  description: The Renuo CLI automates some commonly used workflows by providing a command
210
252
  line interface.
211
253
  email:
@@ -247,12 +289,15 @@ files:
247
289
  - lib/renuo/cli/app/release_project.rb
248
290
  - lib/renuo/cli/app/services/cloudfront_config_service.rb
249
291
  - lib/renuo/cli/app/services/markdown_parser_service.rb
292
+ - lib/renuo/cli/app/setup_uptimerobot.rb
250
293
  - lib/renuo/cli/app/upgrade_laptop.rb
251
294
  - lib/renuo/cli/app/upgrade_laptop/run_command.rb
252
295
  - lib/renuo/cli/app/upgrade_laptop/upgrade_laptop_execution.rb
253
296
  - lib/renuo/cli/app/upgrade_laptop/upgrade_mac_os.rb
254
297
  - lib/renuo/cli/version.rb
255
298
  - renuo-cli.gemspec
299
+ - vcr_cassettes/successful_uptimerobot_calls.yml
300
+ - vcr_cassettes/unsuccessful_uptimerobot_calls.yml
256
301
  homepage: https://github.com/renuo/renuo-cli
257
302
  licenses:
258
303
  - MIT