firespring_dev_commands 2.1.26 → 2.1.27.pre.alpha.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: 14012894728c84550e3d2b59fad8fda3792ed8c6a548115b3a95dd0580420cd1
4
- data.tar.gz: 77315bb5bbcfc940253870fc070911f8f23aeb6536dc38f9b768b8749676f3a4
3
+ metadata.gz: 1f810ca7ab797bb1ec56674b67d42de056d5f88cd95a8e9c45b67d26a3570d19
4
+ data.tar.gz: 487bdc8a74717f11bb48b5b81a33093fde87ddb2b44d97cdf84a0372e3b93627
5
5
  SHA512:
6
- metadata.gz: 576bdab4cbf3e569fef9114a1e5d413e8b9495da3b6ef546d0121e8aaa68af1e3d3232e85e5ec9c2ef1cc47e7ffb089c5badade94c5f4edce24e63c2b9cf091c
7
- data.tar.gz: 4d6c01abd25e937f02c8629b10ce1380eb8a2d65ce7cf1afc86be0fd58311fb88d76d437754e4155bea3bbbe85983c482479b76356a8e99e00e5ee87e224f1f2
6
+ metadata.gz: 212273f4a640214bf8001c12419f33bb6dc621dc37a29b95e75d06c5b5e4bd3f7b7231c003cd032ed1be1c2dc0667d3474fb74892a7577ddd57eca248d96ab09
7
+ data.tar.gz: 480720fd9de858a1ce969644958e61238e866fef1126fb91909992eca3301275d04fd42df45c1f34a7c5126758172a4c89f7bfc0ea3c1b8e2528816de97dbfba
@@ -0,0 +1,59 @@
1
+ module Dev
2
+ # Class contains methods for requesting a certificate from route53.
3
+ # You must have a hosted zone defined for the desired domain
4
+ class Certificate
5
+ attr_accessor :domains, :email
6
+
7
+ def initialize(domains, email)
8
+ @domains = Array(domains)
9
+ @email = email
10
+ raise 'No certificate domains specified' if domains.empty?
11
+ end
12
+
13
+ # Request the certificate using the route53 docker image
14
+ # Certificate is stored in /etc/letsencrypt
15
+ def request
16
+ puts
17
+ puts 'Getting SSL Certs For:'
18
+ puts domains.join("\n")
19
+ puts
20
+ puts 'This process can take up to 10 minutes'
21
+ puts
22
+ puts Time.now
23
+
24
+ # TODO: Really should use the docker api for this
25
+ cmd = %w(docker run -it --rm --name certbot)
26
+ cmd << '-e' << 'AWS_ACCESS_KEY_ID'
27
+ cmd << '-e' << 'AWS_SECRET_ACCESS_KEY'
28
+ cmd << '-e' << 'AWS_SESSION_TOKEN'
29
+ cmd << '-v' << '/etc/letsencrypt:/etc/letsencrypt'
30
+ cmd << 'certbot/dns-route53:latest'
31
+ cmd << 'certonly'
32
+ cmd << '-n'
33
+ cmd << '--agree-tos'
34
+ cmd << '--dns-route53'
35
+ cmd << '-d' << domains.join(',')
36
+ cmd << '--email' << email
37
+ cmd << '--server' << 'https://acme-v02.api.letsencrypt.org/directory'
38
+ puts cmd.join(' ')
39
+ Dev::Common.new.run_command(cmd)
40
+ end
41
+
42
+ # Saves the latest version of the certificate into the given dest_dir
43
+ def save(dest_dir)
44
+ raise "directory #{dest_dir} must be an existing directory" unless File.directory?(dest_dir)
45
+
46
+ domain = domains.first.sub(/^\*\./, '')
47
+ directories = Dir.glob("/etc/letsencrypt/live/#{domain}*/")
48
+ no_suffix = directories.delete("/etc/letsencrypt/live/#{domain}/")
49
+ biggest_suffix = directories.max
50
+ source_dir = biggest_suffix || no_suffix
51
+ raise "unable to determine certificate directory for #{domain}" unless source_dir
52
+
53
+ FileUtils.cp("#{source_dir}privkey.pem", dest_dir, verbose: true)
54
+ FileUtils.cp("#{source_dir}cert.pem", dest_dir, verbose: true)
55
+ FileUtils.cp("#{source_dir}chain.pem", dest_dir, verbose: true)
56
+ FileUtils.cp("#{source_dir}fullchain.pem", dest_dir, verbose: true)
57
+ end
58
+ end
59
+ end
@@ -187,14 +187,5 @@ module Dev
187
187
  return false
188
188
  end
189
189
  end
190
-
191
- # Center the string and pad on either side with the given padding character
192
- def center_pad(string = '', pad: '-', len: 80)
193
- string = " #{string} " unless string.strip.empty?
194
- center_dash = len / 2
195
- string = string.to_s
196
- center_str = string.length / 2
197
- string.rjust(center_dash + center_str - 1, pad).ljust(len - 1, pad)
198
- end
199
190
  end
200
191
  end
@@ -33,6 +33,26 @@ module Dev
33
33
  EXITED,
34
34
  DEAD
35
35
  ].freeze
36
+
37
+ # TODO: Can we use 'curses' here and overwrite the correct line?
38
+ def response_callback(response)
39
+ response.split("\n").each do |line|
40
+ data = JSON.parse(line)
41
+ if data.include?('status')
42
+ if data['id']
43
+ LOG.info "#{data['id']}: #{data['status']}"
44
+ else
45
+ LOG.info (data['status']).to_s
46
+ end
47
+ elsif data.include?('errorDetail')
48
+ raise data['errorDetail']['message']
49
+ elsif data.include?('aux')
50
+ next
51
+ else
52
+ raise "Unrecognized message from docker: #{data}"
53
+ end
54
+ end
55
+ end
36
56
  end
37
57
  end
38
58
  end
@@ -117,6 +117,44 @@ module Dev
117
117
  format('%.1f %s', size.to_f / (1024**exp), units[exp])
118
118
  end
119
119
 
120
+ # Push the local version of the docker image to the defined remote repository
121
+ def push_image(image, name, tag = nil)
122
+ unless tag
123
+ if name.include?(':')
124
+ name, tag = name.split(':')
125
+ else
126
+ tag = 'latest'
127
+ end
128
+ end
129
+
130
+ puts "Pushing to #{name}:#{tag}"
131
+ image.push(::Docker.creds, repo_tag: "#{name}:#{tag}") { |response| Dev::Docker::Status.new.response_callback(response) }
132
+ end
133
+
134
+ # Push the remote version of the docker image from the defined remote repository
135
+ def pull_image(name, tag = nil)
136
+ unless tag
137
+ if name.include?(':')
138
+ name, tag = name.split(':')
139
+ else
140
+ tag = 'latest'
141
+ end
142
+ end
143
+
144
+ puts "\nPulling #{name}:#{tag}"
145
+ opts = {
146
+ fromImage: "#{name}:#{tag}",
147
+ platform: Dev::Common::Platform.new.architecture
148
+ }
149
+ ::Docker::Image.create(**opts) { |response| Dev::Docker::Status.new.response_callback(response) }
150
+ end
151
+
152
+ # Remove the local version of the given docker image
153
+ def untag_image(image, name, tag)
154
+ puts "Untagging #{name}:#{tag}"
155
+ image.remove(name: "#{name}:#{tag}")
156
+ end
157
+
120
158
  # Remove docker images with the "force" option set to true
121
159
  # This will remove the images even if they are currently in use and cause unintended side effects.
122
160
  def force_remove_images(name_and_tag)
@@ -46,23 +46,13 @@ module Dev
46
46
  @products
47
47
  end
48
48
 
49
- # Prints all of the product version statuses
50
- def status
51
- product_versions.sort_by(&:name).each(&:print_status)
52
- end
53
-
54
- # Returns true if any of the products are EOL
55
- def eol?
56
- product_versions.any?(&:eol)
57
- end
58
-
59
49
  # Prints all of the product version statuses
60
50
  # Raises an error if any products are EOL
61
51
  def check
62
52
  puts
63
- status
53
+ product_versions.sort_by(&:name).each(&:print_status)
64
54
  puts
65
- raise 'found EOL versions' if eol?
55
+ raise 'found EOL versions' if product_versions.any?(&:eol)
66
56
  end
67
57
  end
68
58
  end
@@ -113,10 +113,10 @@ module Dev
113
113
  next unless File.exist?(project_dir)
114
114
 
115
115
  repo_basename = File.basename(File.realpath(project_dir))
116
- header = "#{repo_basename} (#{original_branches[project_dir]})"
117
- puts Dev::Common.new.center_pad(header).light_green
116
+ header = " #{repo_basename} (#{original_branches[project_dir]}) "
117
+ puts center_pad(header).light_green
118
118
  @success &= status(dir: project_dir)
119
- puts Dev::Common.new.center_pad.light_green
119
+ puts center_pad.light_green
120
120
  end
121
121
  puts
122
122
 
@@ -165,10 +165,10 @@ module Dev
165
165
  next unless File.exist?(project_dir)
166
166
 
167
167
  repo_basename = File.basename(File.realpath(project_dir))
168
- header = "#{repo_basename} (#{original_branches[project_dir]})"
169
- puts Dev::Common.new.center_pad(header).light_green
168
+ header = " #{repo_basename} (#{original_branches[project_dir]}) "
169
+ puts center_pad(header).light_green
170
170
  reset(dir: project_dir)
171
- puts Dev::Common.new.center_pad.light_green
171
+ puts center_pad.light_green
172
172
  end
173
173
  puts
174
174
  end
@@ -191,9 +191,10 @@ module Dev
191
191
  next unless File.exist?(project_dir)
192
192
 
193
193
  repo_basename = File.basename(File.realpath(project_dir))
194
- puts Dev::Common.new.center_pad(repo_basename).light_green
194
+ header = " #{repo_basename} "
195
+ puts center_pad(header).light_green
195
196
  @success &= checkout(branch, dir: project_dir)
196
- puts Dev::Common.new.center_pad.light_green
197
+ puts center_pad.light_green
197
198
  end
198
199
  puts
199
200
 
@@ -284,9 +285,10 @@ module Dev
284
285
  next unless File.exist?(project_dir)
285
286
 
286
287
  repo_basename = File.basename(File.realpath(project_dir))
287
- puts Dev::Common.new.center_pad(repo_basename).light_green
288
+ header = " #{repo_basename} "
289
+ puts center_pad(header).light_green
288
290
  @success &= merge(branch, dir: project_dir)
289
- puts Dev::Common.new.center_pad.light_green
291
+ puts center_pad.light_green
290
292
  end
291
293
  puts
292
294
 
@@ -332,9 +334,10 @@ module Dev
332
334
  next unless File.exist?(project_dir)
333
335
 
334
336
  repo_basename = File.basename(File.realpath(project_dir))
335
- puts Dev::Common.new.center_pad(repo_basename).light_green
337
+ header = " #{repo_basename} "
338
+ puts center_pad(header).light_green
336
339
  @success &= pull(dir: project_dir)
337
- puts Dev::Common.new.center_pad.light_green
340
+ puts center_pad.light_green
338
341
  end
339
342
  puts
340
343
 
@@ -370,9 +373,10 @@ module Dev
370
373
  next unless File.exist?(project_dir)
371
374
 
372
375
  repo_basename = File.basename(File.realpath(project_dir))
373
- puts Dev::Common.new.center_pad(repo_basename).light_green
376
+ header = " #{repo_basename} "
377
+ puts center_pad(header).light_green
374
378
  @success &= push(dir: project_dir)
375
- puts Dev::Common.new.center_pad.light_green
379
+ puts center_pad.light_green
376
380
  end
377
381
  puts
378
382
 
@@ -435,10 +439,11 @@ module Dev
435
439
  end
436
440
 
437
441
  # Center the string and pad on either side with the given padding character
438
- # @deprecated Please use {Dev::Common#center_pad} instead
439
442
  def center_pad(string = '', pad: '-', len: 80)
440
- warn '[DEPRECATION] `Dev::Git#center_pad` is deprecated. Please use `Dev::Common#center_pad` instead.'
441
- Dev::Common.new.center_pad(string, pad:, len:)
443
+ center_dash = len / 2
444
+ string = string.to_s
445
+ center_str = string.length / 2
446
+ string.rjust(center_dash + center_str - 1, pad).ljust(len - 1, pad)
442
447
  end
443
448
 
444
449
  # Exclude the command from the message and print all error lines
@@ -90,16 +90,14 @@ module Dev
90
90
 
91
91
  # Build the bundle lint command
92
92
  def lint_command
93
- lint = base_command
94
- lint << 'exec' << 'rubocop'
93
+ lint = ['rubocop']
95
94
  lint.concat(Dev::Common.new.tokenize(ENV['OPTS'].to_s))
96
95
  lint
97
96
  end
98
97
 
99
98
  # Build the bundle lint fix command
100
99
  def lint_fix_command
101
- lint_fix = base_command
102
- lint_fix << 'exec' << 'rubocop'
100
+ lint_fix = ['rubocop']
103
101
  lint_fix << '-A'
104
102
  lint_fix.concat(Dev::Common.new.tokenize(ENV['OPTS'].to_s))
105
103
  lint_fix
@@ -107,8 +105,7 @@ module Dev
107
105
 
108
106
  # Build the bundle test command
109
107
  def test_command
110
- test = base_command
111
- test << 'exec' << 'rspec'
108
+ test = ['rspec']
112
109
  test.concat(Dev::Common.new.tokenize(ENV['OPTS'].to_s))
113
110
  test
114
111
  end
@@ -101,22 +101,14 @@ module Dev
101
101
 
102
102
  DEV_COMMANDS_TOP_LEVEL.instance_eval do
103
103
  return if exclude.include?(:eol)
104
- return if ENV.fetch('CHECK_AWS', nil).to_s.strip == 'false'
105
104
 
106
- task eol: [:'eol:aws'] do
107
- # This is just a placeholder to execute the dependencies
108
- end
105
+ desc 'Compares the current date to the EOL date for supported resources'
106
+ task eol: %w(init ensure_aws_credentials) do
107
+ account_id = Dev::Aws::Profile.new.current
108
+ account_name = Dev::Aws::Account.new.name_by_account(account_id)
109
+ LOG.info " Current AWS Account is #{account_name} (#{account_id})".light_yellow
109
110
 
110
- namespace :eol do
111
- desc 'Compares the current date to the EOL date for supported aws resources'
112
- task aws: %w(init ensure_aws_credentials) do
113
- account_id = Dev::Aws::Profile.new.current
114
- account_name = Dev::Aws::Account.new.name_by_account(account_id)
115
- LOG.info " Current AWS Account is #{account_name} (#{account_id})".light_yellow
116
- puts
117
- Dev::EndOfLife.new(product_versions: Dev::EndOfLife::Aws.new.default_products).status
118
- puts
119
- end
111
+ Dev::EndOfLife.new(product_versions: Dev::EndOfLife::Aws.new.default_products).check
120
112
  end
121
113
  end
122
114
  end
@@ -0,0 +1,41 @@
1
+ require_relative 'base_interface'
2
+
3
+ module Dev
4
+ module Template
5
+ # Class contains rake templates for managing configured certificates
6
+ class Certificate < Dev::Template::BaseInterface
7
+ attr_reader :names, :email, :paths
8
+
9
+ def initialize(names, email:, paths:, exclude: [])
10
+ @names = names
11
+ @email = email
12
+ @paths = Array(paths)
13
+
14
+ super(exclude:)
15
+ end
16
+
17
+ # Create the rake task for the generate method
18
+ def create_generate_task!
19
+ # Have to set a local variable to be accessible inside of the instance_eval block
20
+ names = @names
21
+ email = @email
22
+ paths = @paths
23
+ exclude = @exclude
24
+
25
+ DEV_COMMANDS_TOP_LEVEL.instance_eval do
26
+ return if exclude.include?(:generate)
27
+
28
+ namespace :certificate do
29
+ desc 'Requests a new certificate for the configured domain using the route53 validation and deposits it in the configured paths'
30
+ task generate: %w(init_docker ensure_aws_credentials) do
31
+ Dev::Docker.new.pull_image('certbot/dns-route53', 'latest')
32
+ c = Dev::Certificate.new(names, email)
33
+ c.request
34
+ paths.each { |path| c.save(path) }
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -29,7 +29,6 @@ module Dev
29
29
  end
30
30
 
31
31
  # Create the rake task which runs linting for the application name
32
- # rubocop:disable Metrics/MethodLength
33
32
  def create_lint_task!
34
33
  application = @name
35
34
  node = @node
@@ -43,13 +42,6 @@ module Dev
43
42
  # This is just a placeholder to execute the dependencies
44
43
  end
45
44
 
46
- namespace :lint do
47
- desc 'Run all linting software and apply all available fixes'
48
- task fix: %w(node:lint:fix) do
49
- # This is just a placeholder to execute the dependencies
50
- end
51
- end
52
-
53
45
  namespace :node do
54
46
  desc "Run the node linting software against the #{application}'s codebase"
55
47
  task lint: %w(init_docker up_no_deps) do
@@ -74,7 +66,6 @@ module Dev
74
66
  end
75
67
  end
76
68
  end
77
- # rubocop:enable Metrics/MethodLength
78
69
 
79
70
  # Create the rake task which runs all tests for the application name
80
71
  def create_test_task!
@@ -74,7 +74,6 @@ module Dev
74
74
  end
75
75
 
76
76
  # Create the rake task which runs linting for the application name
77
- # rubocop:disable Metrics/MethodLength
78
77
  def create_lint_task!
79
78
  application = @name
80
79
  php = @php
@@ -88,13 +87,6 @@ module Dev
88
87
  # This is just a placeholder to execute the dependencies
89
88
  end
90
89
 
91
- namespace :lint do
92
- desc 'Run all linting software and apply all available fixes'
93
- task fix: %w(php:lint:fix) do
94
- # This is just a placeholder to execute the dependencies
95
- end
96
- end
97
-
98
90
  namespace :php do
99
91
  desc "Run the php linting software against the #{application}'s codebase"
100
92
  task lint: %w(init_docker up_no_deps) do
@@ -119,7 +111,6 @@ module Dev
119
111
  end
120
112
  end
121
113
  end
122
- # rubocop:enable Metrics/MethodLength
123
114
 
124
115
  # Create the rake task which runs all tests for the application name
125
116
  def create_test_task!
@@ -28,7 +28,6 @@ module Dev
28
28
  end
29
29
 
30
30
  # Create the rake task which runs linting for the application name
31
- # rubocop:disable Metrics/MethodLength
32
31
  def create_lint_task!
33
32
  application = @name
34
33
  ruby = @ruby
@@ -42,13 +41,6 @@ module Dev
42
41
  # This is just a placeholder to execute the dependencies
43
42
  end
44
43
 
45
- namespace :lint do
46
- desc 'Run all linting software and apply all available fixes'
47
- task fix: %w(ruby:lint:fix) do
48
- # This is just a placeholder to execute the dependencies
49
- end
50
- end
51
-
52
44
  namespace :ruby do
53
45
  desc "Run the ruby linting software against the #{application}'s codebase"
54
46
  task lint: %w(init_docker up_no_deps) do
@@ -73,7 +65,6 @@ module Dev
73
65
  end
74
66
  end
75
67
  end
76
- # rubocop:enable Metrics/MethodLength
77
68
 
78
69
  # Create the rake task which runs all tests for the application name
79
70
  def create_test_task!
@@ -12,10 +12,9 @@ module Dev
12
12
  DEV_COMMANDS_TOP_LEVEL.instance_eval do
13
13
  return if exclude.include?(:eol)
14
14
 
15
- desc 'Compares the current date to the EOL date for all configured projects' \
16
- "\n\toptionally specify CHECK_AWS=<true/false> to toggle whether AWS resources are checked for EOL (defaults to true)"
15
+ desc 'Compares the current date to the EOL date for all configured projects'
17
16
  task eol: %w(init) do
18
- Dev::EndOfLife.new.status
17
+ Dev::EndOfLife.new.check
19
18
  end
20
19
  end
21
20
  end
@@ -4,23 +4,6 @@ module Dev
4
4
  module Template
5
5
  # Class contains rake templates for managing your git project
6
6
  class Git < Dev::Template::BaseInterface
7
- # Create the rake task for cloning all defined repos
8
- def create_clone_task!
9
- # Have to set a local variable to be accessible inside of the instance_eval block
10
- exclude = @exclude
11
-
12
- DEV_COMMANDS_TOP_LEVEL.instance_eval do
13
- namespace :git do
14
- return if exclude.include?(:clone)
15
-
16
- desc 'Make sure all repos are cloned'
17
- task :clone do
18
- Dev::Git.new.clone_repos
19
- end
20
- end
21
- end
22
- end
23
-
24
7
  # Create the rake task for the git checkout method
25
8
  def create_checkout_task!
26
9
  # Have to set a local variable to be accessible inside of the instance_eval block
@@ -6,6 +6,6 @@ module Dev
6
6
  # Use 'v.v.v.pre.alpha.v' for pre-release vesions
7
7
  # Use 'v.v.v.beta.v for beta versions
8
8
  # Use semantic versioning for any releases (https://semver.org/)
9
- VERSION = '2.1.26'.freeze
9
+ VERSION = '2.1.27.pre.alpha.1'.freeze
10
10
  end
11
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: firespring_dev_commands
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.26
4
+ version: 2.1.27.pre.alpha.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Firespring
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-26 00:00:00.000000000 Z
11
+ date: 2024-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -332,6 +332,7 @@ files:
332
332
  - lib/firespring_dev_commands/bloom_growth/seat.rb
333
333
  - lib/firespring_dev_commands/bloom_growth/user.rb
334
334
  - lib/firespring_dev_commands/boolean.rb
335
+ - lib/firespring_dev_commands/certificate.rb
335
336
  - lib/firespring_dev_commands/common.rb
336
337
  - lib/firespring_dev_commands/coverage/base.rb
337
338
  - lib/firespring_dev_commands/coverage/cobertura.rb
@@ -383,6 +384,7 @@ files:
383
384
  - lib/firespring_dev_commands/target_process/user_story_history.rb
384
385
  - lib/firespring_dev_commands/templates/aws.rb
385
386
  - lib/firespring_dev_commands/templates/base_interface.rb
387
+ - lib/firespring_dev_commands/templates/certificate.rb
386
388
  - lib/firespring_dev_commands/templates/ci.rb
387
389
  - lib/firespring_dev_commands/templates/config.rb
388
390
  - lib/firespring_dev_commands/templates/docker/application.rb
@@ -409,9 +411,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
409
411
  version: '3.1'
410
412
  required_rubygems_version: !ruby/object:Gem::Requirement
411
413
  requirements:
412
- - - ">="
414
+ - - ">"
413
415
  - !ruby/object:Gem::Version
414
- version: '0'
416
+ version: 1.3.1
415
417
  requirements: []
416
418
  rubygems_version: 3.4.10
417
419
  signing_key: