firespring_dev_commands 3.1.6 → 3.1.7.pre.alpha.0

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: 06d3d669c29312665a6b6149c065e363d583f06dc71cee74f32afdd90b90fe02
4
- data.tar.gz: 8afcc297e1cfb716b2ecde123a8ce844d667f5b5eebed7f1381b8ef184aa5b54
3
+ metadata.gz: 8275d05348558ebee7666f8f3b10492a5c03ac4128d687121fa26f37c6624947
4
+ data.tar.gz: 52c525b7b85f31eabed89344bd1d0fedd879f567524b107f2883d76aee38b61f
5
5
  SHA512:
6
- metadata.gz: 9e49babaef1561dd8677316d3a0b503e16366524337bf8e5daa44dc27048a73a996f75e4d0fb8359f2457efe139c398b383b842d3c986f9d80d583a050d2e799
7
- data.tar.gz: 4ae19938da453756bef33502ac9af8d47c5361e76f4c676882ebe10e70df7ef77bc792c81d49131086a52d10d465038a520c82958b55fdd4b3a8fbde339fbd64
6
+ metadata.gz: '028f6f4934a5fabeaf2a7f8bb1ac33e945d481f0c889a1ea12346c651009389e62a62360d42861fb6225919e34ac0779628cfd0a5af1665d5f9b0fad8945593d'
7
+ data.tar.gz: 84d7ef04427cf9e3f1024cf76c7262fec1a96a2106cd56ceddeb34aad77ee4cc78f3eed53baacf533b58936126fb70ec4ad83b394ebc933adc6d2fe26f1ef0a0
@@ -61,15 +61,15 @@ module Dev
61
61
  puts " Logging in to #{account} in #{region} as #{role}".light_yellow
62
62
  puts
63
63
 
64
- code = ENV['AWS_TOKEN_CODE'] || Dev::Common.new.ask("Enter the MFA code for the #{ENV.fetch('USERNAME', 'no_username_found')} user serial #{serial}")
64
+ code = mfa_code(serial)
65
65
  raise 'MFA is required' unless code.to_s.strip
66
66
 
67
67
  sts = ::Aws::STS::Client.new(profile: 'default', region:)
68
68
  creds = sts.assume_role(
69
- serial_number: serial,
69
+ serial_number: mfa_serial || serial,
70
70
  role_arn: role,
71
71
  role_session_name: session_name,
72
- token_code: code,
72
+ token_code: code.to_s.strip,
73
73
  duration_seconds: session_duration
74
74
  ).credentials
75
75
  puts
@@ -77,6 +77,32 @@ module Dev
77
77
  Dev::Aws::Credentials.new.write!(account, creds)
78
78
  end
79
79
 
80
+ # The custom local file where target information is stored.
81
+ CUSTOM_CONFIG_FILE = "#{Dir.home}/.bash_profile.d/config/.main".freeze
82
+
83
+ # Targets a custom ini config.
84
+ def custom_config_ini
85
+ IniFile.new(filename: CUSTOM_CONFIG_FILE, default: 'default')['default']
86
+ end
87
+
88
+ def mfa_serial
89
+ return unless !ENV.fetch('OP_LOGIN', nil).nil? && File.exist?(CUSTOM_CONFIG_FILE)
90
+
91
+ custom_config_ini['aws_1pass_mfa_serial']
92
+ end
93
+
94
+ # Handles the MFA code logic.
95
+ def mfa_code(serial)
96
+ # Note, OP_LOGIN likely not needed. Available as feature flag.
97
+ # Checks if OnePassword CLI is installed and the custom config file exist.
98
+ if !ENV.fetch('OP_LOGIN', nil).nil? && system('op --version', out: '/dev/null') && File.exist?(CUSTOM_CONFIG_FILE)
99
+ cmd = "op item get #{custom_config_ini['aws_uuid']} --otp"
100
+ `#{cmd}`
101
+ else
102
+ ENV['AWS_TOKEN_CODE'] || Dev::Common.new.ask("Enter the MFA code for the #{ENV.fetch('USERNAME', 'no_username_found')} user serial #{serial}")
103
+ end
104
+ end
105
+
80
106
  # Returns the config ini file
81
107
  # Runs the setup for our current account if it's not already setup
82
108
  def setup_cfgini(account)
@@ -88,8 +114,8 @@ module Dev
88
114
  cfgini
89
115
  end
90
116
 
91
- # Authroizes the docker cli to pull/push images from the Aws container registry (e.g. if docker compose needs to pull an image)
92
- # Authroizes the docker ruby library to pull/push images from the Aws container registry
117
+ # Authorizes the docker cli to pull/push images from the Aws container registry (e.g. if docker compose needs to pull an image)
118
+ # Authorizes the docker ruby library to pull/push images from the Aws container registry
93
119
  def registry_logins!(registry_ids: nil, region: nil)
94
120
  registry_ids ||= Dev::Aws::Account.new.ecr_registry_ids
95
121
  region ||= Dev::Aws::Credentials.new.logged_in_region || Dev::Aws::DEFAULT_REGION
@@ -100,8 +126,8 @@ module Dev
100
126
  puts
101
127
  end
102
128
 
103
- # Authroizes the docker cli to pull/push images from the Aws container registry (e.g. if docker compose needs to pull an image)
104
- # Authroizes the docker ruby library to pull/push images from the Aws container registry
129
+ # Authorizes the docker cli to pull/push images from the Aws container registry (e.g. if docker compose needs to pull an image)
130
+ # Authorizes the docker ruby library to pull/push images from the Aws container registry
105
131
  def registry_login!(registry_id: nil, region: nil)
106
132
  registry_id ||= Dev::Aws::Account.new.ecr_registry_ids.first
107
133
  region ||= Dev::Aws::Credentials.new.logged_in_region || Dev::Aws::DEFAULT_REGION
@@ -238,7 +238,8 @@ module Dev
238
238
 
239
239
  # Merges two arrays removing nested structure and duplicate keys
240
240
  private def merge_options(*opts)
241
- @options = (@options + Array(opts)).flatten.uniq
241
+ puts 'WARNING: merging options disabled' if @options.any? { |it| it.include?('--build-arg') }
242
+ @options = (@options + Array(opts)).flatten.uniq unless @options.any? { |it| it.include?('--build-arg') }
242
243
  end
243
244
 
244
245
  # Build the compose command with the given inputs
@@ -34,5 +34,28 @@ module Dev
34
34
  end
35
35
  end
36
36
  end
37
+
38
+ def containerized?
39
+ # Fast path: common flags files
40
+ return true if File.exist?('/.dockerenv') # Docker
41
+ return true if File.exist?('/run/.containerenv') # Podman / some runtimes
42
+
43
+ # Env flags some images set
44
+ return true if ENV['DOCKER_CONTAINER'] == 'true'
45
+ return true if ENV['container']&.match?(/docker|podman|lxc|containerd/i)
46
+
47
+ # cgroup hints (docker, containerd, kubernetes, podman)
48
+ %w(/proc/1/cgroup /proc/self/cgroup).any? do |p|
49
+ next false unless File.readable?(p)
50
+
51
+ File.read(p).match?(/docker|containerd|kubepods|podman|libpod/i)
52
+ end
53
+ rescue
54
+ false
55
+ end
56
+
57
+ def on_host
58
+ yield unless containerized?
59
+ end
37
60
  end
38
61
  end
@@ -53,7 +53,7 @@ module Dev
53
53
  detail = JSON.parse(response.body) if response.is_a?(Net::HTTPSuccess)
54
54
 
55
55
  # If EOL info is a boolean or missing from the current details, overwrite with the manual date (if present)
56
- manual_date = Dev::EndOfLife.config.manual_dates["#{product}_#{cycle.tr('.', '_')}".to_sym]
56
+ manual_date = Dev::EndOfLife.config.manual_dates[:"#{product}_#{cycle.tr('.', '_')}"]
57
57
  detail['eol'] = manual_date if manual_date && (detail['eol'].boolean? || detail['eol'].nil?)
58
58
  detail['eol'] = '1979-01-01' if detail.empty?
59
59
  detail
@@ -185,7 +185,7 @@ module Dev
185
185
  end
186
186
 
187
187
  # Checks out the given branch in all repositories with some additional formatting
188
- def checkout_all(branch)
188
+ def checkout_all(branch, default)
189
189
  @success = true
190
190
  puts
191
191
  puts "Checking out #{branch} in each repo".light_yellow if project_dirs.length > 1
@@ -194,7 +194,7 @@ module Dev
194
194
 
195
195
  repo_basename = File.basename(File.realpath(project_dir))
196
196
  puts Dev::Common.new.center_pad(repo_basename).light_green
197
- @success &= checkout(branch, dir: project_dir)
197
+ @success &= checkout(branch, default, dir: project_dir)
198
198
  puts Dev::Common.new.center_pad.light_green
199
199
  end
200
200
  puts
@@ -203,9 +203,10 @@ module Dev
203
203
  end
204
204
 
205
205
  # Checks out the given branch in the given repo
206
+ # If the given branch isn't found, falls back to default branch, then staging, then main
206
207
  # Defaults to the current directory
207
208
  # optionally raise errors
208
- def checkout(branch, dir: default_project_dir, raise_errors: false)
209
+ def checkout(branch, default, dir: default_project_dir, raise_errors: false)
209
210
  raise 'branch is required' if branch.to_s.strip.empty?
210
211
  return unless File.exist?(dir)
211
212
 
@@ -215,10 +216,11 @@ module Dev
215
216
  g = ::Git.open(dir)
216
217
  g.fetch('origin', prune: true)
217
218
 
218
- # If the branch we are checking out doesn't exist, check out either the staging branch or the main branch
219
+ # If the branch we are checking out doesn't exist,
220
+ # check out either the default branch, staging branch, or the main branch
219
221
  actual_branch = branch
220
222
  unless branch_exists?(dir, branch)
221
- actual_branch = [staging_branch, main_branch].uniq.find { |it| branch_exists?(dir, it) }
223
+ actual_branch = [default, staging_branch, main_branch].uniq.find { |it| branch_exists?(dir, it) }
222
224
  puts "Branch #{branch} not found, checking out #{actual_branch} instead".light_yellow
223
225
  end
224
226
 
@@ -6,7 +6,7 @@ module Dev
6
6
 
7
7
  def initialize(data)
8
8
  @name = data.project.name
9
- @name = @name << ' DevOps' if /devops/i.match?(data.issuetype.name)
9
+ @name <<= ' DevOps' if /devops/i.match?(data.issuetype.name)
10
10
  end
11
11
  end
12
12
  end
@@ -95,7 +95,9 @@ module Dev
95
95
  # Build the bundle lint command
96
96
  def lint_command
97
97
  lint = base_command
98
- lint << 'exec' << 'rake' << 'lint'
98
+ target_lint = Dev::Env.new.containerized? ? %w(rake lint) : ['rubocop']
99
+ lint << 'exec'
100
+ lint.concat(target_lint)
99
101
  lint.concat(Dev::Common.new.tokenize(ENV['OPTS'].to_s))
100
102
  lint
101
103
  end
@@ -103,7 +105,9 @@ module Dev
103
105
  # Build the bundle lint fix command
104
106
  def lint_fix_command
105
107
  lint_fix = base_command
106
- lint_fix << 'exec' << 'rake' << 'lint:fix'
108
+ target_lint = Dev::Env.new.containerized? ? %w(rake lint:fix) : %w(rubocop -A)
109
+ lint_fix << 'exec'
110
+ lint_fix.concat(target_lint)
107
111
  lint_fix.concat(Dev::Common.new.tokenize(ENV['OPTS'].to_s))
108
112
  lint_fix
109
113
  end
@@ -111,7 +115,9 @@ module Dev
111
115
  # Build the bundle test command
112
116
  def test_command
113
117
  test = base_command
114
- test << 'exec' << 'rake' << 'test'
118
+ target_test = Dev::Env.new.containerized? ? %w(rake test) : ['rspec']
119
+ test << 'exec'
120
+ test.concat(target_test)
115
121
  test.concat(coverage.ruby_options) if coverage
116
122
  test.concat(Dev::Common.new.tokenize(ENV['OPTS'].to_s))
117
123
  test
@@ -74,7 +74,7 @@ module Dev
74
74
  # Run the lint command
75
75
  options = []
76
76
  options << '-T' if Dev::Common.new.running_codebuild?
77
- environment = ['OPTS']
77
+ environment = %w(OPTS)
78
78
  Dev::Docker::Compose.new(services: application, options:, environment:).exec(*ruby.lint_command)
79
79
  ensure
80
80
  # Copy any defined artifacts back
@@ -92,7 +92,7 @@ module Dev
92
92
  # Run the lint fix command
93
93
  options = []
94
94
  options << '-T' if Dev::Common.new.running_codebuild?
95
- environment = ['OPTS']
95
+ environment = %w(OPTS)
96
96
  Dev::Docker::Compose.new(services: application, options:, environment:).exec(*ruby.lint_fix_command)
97
97
  end
98
98
  end
@@ -190,7 +190,7 @@ module Dev
190
190
  namespace :ruby do
191
191
  desc 'Install all bundled gems'
192
192
  task install: %w(init_docker up_no_deps) do
193
- environment = ['OPTS']
193
+ environment = %w(OPTS)
194
194
  Dev::Docker::Compose.new(services: application, environment:).exec(*ruby.install_command)
195
195
  end
196
196
  end
@@ -31,13 +31,15 @@ module Dev
31
31
  return if exclude.include?(:checkout)
32
32
 
33
33
  desc 'Checks out a branch for each repo (alias: git:co)' \
34
- "\n\tuse BRANCH=abc123 to specify the branch of code you with to switch to (required)" \
35
- "\n\tIf the branch does not exist, the configured staging or main branch will be checked out"
34
+ "\n\tuse BRANCH=abc123 to specify the branch of code you wish to switch to (required)" \
35
+ "\n\tuse DEFAULT=abc456 to specify the branch of code to fall back to" \
36
+ "\n\tIf branch and default do not exist, the configured staging or main branch will be checked out"
36
37
  task checkout: %w(init) do
37
38
  branch = ENV['BRANCH'].to_s.strip
39
+ default = ENV['DEFAULT'].to_s.strip
38
40
  raise 'branch is required' if branch.empty?
39
41
 
40
- Dev::Git.new.checkout_all(branch)
42
+ Dev::Git.new.checkout_all(branch, default)
41
43
  end
42
44
 
43
45
  task co: %w(init checkout) do
@@ -48,7 +50,7 @@ module Dev
48
50
  [d.main_branch, d.staging_branch].uniq.each do |it|
49
51
  desc "Checks out the #{it} branch for each repo (alias: git:co:#{it})"
50
52
  task "checkout:#{it}": %w(init) do
51
- Dev::Git.new.checkout_all(it)
53
+ Dev::Git.new.checkout_all(it, '')
52
54
  end
53
55
 
54
56
  task "co:#{it}": %W(init checkout:#{it}) do
@@ -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 = '3.1.6'.freeze
9
+ VERSION = '3.1.7.pre.alpha.0'.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: 3.1.6
4
+ version: 3.1.7.pre.alpha.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Firespring
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-13 00:00:00.000000000 Z
11
+ date: 2025-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -476,9 +476,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
476
476
  version: '3.1'
477
477
  required_rubygems_version: !ruby/object:Gem::Requirement
478
478
  requirements:
479
- - - ">="
479
+ - - ">"
480
480
  - !ruby/object:Gem::Version
481
- version: '0'
481
+ version: 1.3.1
482
482
  requirements: []
483
483
  rubygems_version: 3.4.10
484
484
  signing_key: