firespring_dev_commands 1.4.3 → 1.5.0.pre.alpha.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0c6ea353daa4f8fc8157720f6023afdfc136444f029effffc346324cef4de3bf
4
- data.tar.gz: 7f1d10ee1fa396ad27427d6d6acebfe9f8449680179945c227ea29d6d63b6600
3
+ metadata.gz: c00aad2781f73b860860758fa26f0976413ec9917c472a702e4dc93caeffe725
4
+ data.tar.gz: bad9dce8ab37b9e3a71ba479f05fd23405c0ab91abad53ef1f57f2b5f7daf073
5
5
  SHA512:
6
- metadata.gz: 7aa966411494e77d23fd21f908950347b4ee2d67ccc8041f332071700a20c29fca6396b73ec32fe5bc0177ee9b14bd65edc072737e2b9372490a9233e47bb2a4
7
- data.tar.gz: ead151951a9e1fff0d7b01397c7ee5d309f99f9dca13ca66ebf2137ba8ba025374bfafd943286367210e3e2978bf921907321c55e48e7fcbacc0784d7586b838
6
+ metadata.gz: 1818bc0df7bc48e264a95b4a091e0b02776ae9e5fb3f56a06b6e2d39d0bf6aa9ca3275a9af6aba06bd62a139c999951a18fd9859a41601910d6bc986680be4bc
7
+ data.tar.gz: 3259dd964ab887e049166cba3552e3cdc87f9b9e67170acc48363daf3f1495543fd691dbd5be51c63d3cbe44c15ecebbc784f5f4df826fcec452bbbb06caedc8
@@ -4,13 +4,13 @@ module Dev
4
4
  class Account
5
5
  # Config object for setting top level Aws account config options
6
6
  # TODO: registry is deprecated and should be removed on the next major release
7
- Config = Struct.new(:root, :children, :default, :registry, :ecr_registry_ids, :login_to_account_ecr_registry)
7
+ Config = Struct.new(:root, :children, :default, :registry, :ecr_registry_ids, :login_to_account_ecr_registry, :default_login_role_name)
8
8
 
9
9
  # Instantiates a new top level config object if one hasn't already been created
10
10
  # Yields that config object to any given block
11
11
  # Returns the resulting config object
12
12
  def self.config
13
- @config ||= Config.new
13
+ @config ||= Config.new(default_login_role_name: Dev::Aws::DEFAULT_LOGIN_ROLE_NAME)
14
14
  yield(@config) if block_given?
15
15
  @config
16
16
  end
@@ -81,8 +81,13 @@ module Dev
81
81
  region_default = defaultini['region'] || ENV['AWS_DEFAULT_REGION'] || Dev::Aws::DEFAULT_REGION
82
82
  defaultini['region'] = Dev::Common.new.ask('Default region name', region_default)
83
83
 
84
- mfa_default = defaultini['mfa_serial'] || ENV['AWS_MFA_ARN'] || "arn:aws:iam::#{root.id}:mfa/#{ENV.fetch('USERNAME', nil)}"
85
- defaultini['mfa_serial'] = Dev::Common.new.ask('Default mfa arn', mfa_default)
84
+ # NOTE: We had an old config for "mfa_serial" which included the entire arn. We deprecated that config since
85
+ # it made it much more difficult to switch between different root accounts.
86
+ mfa_name_default = defaultini['mfa_serial']&.split(%r{mfa/})&.last || ENV['AWS_MFA_ARN']&.split(%r{mfa/})&.last || ENV.fetch('USERNAME', nil)
87
+ defaultini['mfa_serial_name'] = Dev::Common.new.ask('Default mfa name', mfa_name_default)
88
+ # TODO: Eventually, we should delete the mfa_serial entry from the config. Leaving it for now because some projects
89
+ # may be using older versions of the dev_commands library
90
+ # defaultini.delete('mfa_serial')
86
91
 
87
92
  session_name_default = defaultini['role_session_name'] || "#{ENV.fetch('USERNAME', nil)}_cli"
88
93
  defaultini['role_session_name'] = Dev::Common.new.ask('Default session name', session_name_default)
@@ -119,8 +124,13 @@ module Dev
119
124
  region_default = profileini['region'] || defaultini['region'] || ENV['AWS_DEFAULT_REGION'] || Dev::Aws::DEFAULT_REGION
120
125
  profileini['region'] = Dev::Common.new.ask('Default region name', region_default)
121
126
 
122
- role_default = profileini['role_arn'] || "arn:aws:iam::#{account}:role/ReadonlyAccessRole"
123
- profileini['role_arn'] = Dev::Common.new.ask('Default role arn', role_default)
127
+ # NOTE: We had an old config for "role_arn" which included the entire arn. We deprecated that config since
128
+ # it made it much more difficult to switch between different accounts.
129
+ role_name_default = profileini['role_name'] || profileini['role_arn']&.split(%r{role/})&.last || self.class.config.default_login_role_name
130
+ profileini['role_name'] = Dev::Common.new.ask('Default role name', role_name_default)
131
+ # TODO: Eventually, we should delete the role_arn entry from the config. Leaving it for now because some projects
132
+ # may be using older versions of the dev_commands library
133
+ # profileini.delete('role_arn')
124
134
 
125
135
  cfgini.write
126
136
  end
@@ -75,6 +75,8 @@ module Dev
75
75
  credini = IniFile.new(filename: "#{Dev::Aws::CONFIG_DIR}/credentials", default: 'default')
76
76
  defaultini = credini['default']
77
77
 
78
+ # TODO: Should we allow for multiple sets of base credentials? How do I use this for both FDP and SBF?
79
+
78
80
  access_key_default = defaultini['aws_access_key_id']
79
81
  defaultini['aws_access_key_id'] = Dev::Common.new.ask('AWS Access Key ID', access_key_default)
80
82
 
@@ -31,28 +31,32 @@ module Dev
31
31
  # Temporary credentials are written back to the credentials file
32
32
  def authorize!(account)
33
33
  # Make sure the account has been set up
34
- cfgini = IniFile.new(filename: "#{Dev::Aws::CONFIG_DIR}/config", default: 'default')
35
- unless cfgini.has_section?("profile #{account}")
36
- Dev::Aws::Account.new.write!(account)
37
- cfgini = IniFile.new(filename: "#{Dev::Aws::CONFIG_DIR}/config", default: 'default')
38
- end
34
+ cfgini = setup_cfgini
39
35
 
40
36
  defaultini = cfgini['default']
41
37
  profileini = cfgini["profile #{account}"]
42
38
 
43
- serial = profileini['mfa_serial'] || defaultini['mfa_serial']
44
- role = profileini['role_arn'] || defaultini['role_arn']
39
+ region = profileini['region'] || defaultini['region'] || Dev::Aws::DEFAULT_REGION
40
+
41
+ serial = profileini['mfa_serial_name'] || defaultini['mfa_serial_name']
42
+ serial = "arn:aws:iam::#{Dev::Aws::Account.new.roo.id}:mfa/#{serial}" if serial
43
+ serial ||= profileini['mfa_serial'] || defaultini['mfa_serial']
44
+
45
+ role = profileini['role_name'] || defaultini['role_name']
46
+ role = "arn:aws:iam::#{account}:role/#{role}" if role
47
+ role ||= profileini['role_arn'] || defaultini['role_arn']
48
+
45
49
  session_name = profileini['role_session_name'] || defaultini['role_session_name']
46
50
  session_duration = profileini['session_duration'] || defaultini['session_duration']
47
51
 
48
52
  puts
49
- puts " Logging in to #{account} as #{role}".light_yellow
53
+ puts " Logging in to #{account} in #{region} as #{role}".light_yellow
50
54
  puts
51
55
 
52
56
  code = ENV['AWS_TOKEN_CODE'] || Dev::Common.new.ask("Enter the MFA code for the #{ENV.fetch('USERNAME', '')} user serial #{serial}")
53
57
  raise 'MFA is required' unless code.to_s.strip
54
58
 
55
- sts = ::Aws::STS::Client.new(profile: 'default')
59
+ sts = ::Aws::STS::Client.new(profile: 'default', region: region)
56
60
  creds = sts.assume_role(
57
61
  serial_number: serial,
58
62
  role_arn: role,
@@ -65,9 +69,21 @@ module Dev
65
69
  Dev::Aws::Credentials.new.write!(account, creds)
66
70
  end
67
71
 
72
+ # Returns the config ini file
73
+ # Runs the setup for our current account if it's not already setup
74
+ def setup_cfgini
75
+ cfgini = IniFile.new(filename: "#{Dev::Aws::CONFIG_DIR}/config", default: 'default')
76
+ unless cfgini.has_section?("profile #{account}")
77
+ Dev::Aws::Account.new.write!(account)
78
+ cfgini = IniFile.new(filename: "#{Dev::Aws::CONFIG_DIR}/config", default: 'default')
79
+ end
80
+ cfgini
81
+ end
82
+
68
83
  # Authroizes the docker cli to pull/push images from the Aws container registry (e.g. if docker compose needs to pull an image)
69
84
  # Authroizes the docker ruby library to pull/push images from the Aws container registry
70
- def registry_logins!(registry_ids: Dev::Aws::Account.new.ecr_registry_ids, region: Dev::Aws::DEFAULT_REGION)
85
+ def registry_logins!(registry_ids: Dev::Aws::Account.new.ecr_registry_ids, region: nil)
86
+ region ||= Dev::Aws::Credentials.new.logged_in_region || Dev::Aws::DEFAULT_REGION
71
87
  return if registry_ids.empty?
72
88
 
73
89
  puts
@@ -77,7 +93,8 @@ module Dev
77
93
 
78
94
  # Authroizes the docker cli to pull/push images from the Aws container registry (e.g. if docker compose needs to pull an image)
79
95
  # Authroizes the docker ruby library to pull/push images from the Aws container registry
80
- def registry_login!(registry_id: Dev::Aws::Account.new.ecr_registry_ids.first, region: Dev::Aws::DEFAULT_REGION)
96
+ def registry_login!(registry_id: Dev::Aws::Account.new.ecr_registry_ids.first, region: nil)
97
+ region ||= Dev::Aws::Credentials.new.logged_in_region || Dev::Aws::DEFAULT_REGION
81
98
  raise 'registry_id is required' if registry_id.to_s.strip.empty?
82
99
  raise 'region is required' if region.to_s.strip.empty?
83
100
 
@@ -92,7 +109,8 @@ module Dev
92
109
  # Authroizes the docker cli to pull/push images from the Aws container registry
93
110
  # (e.g. if docker compose needs to pull an image)
94
111
  # @deprecated Please use {Dev::Aws::Login#registry_login!} instead
95
- def docker_login!(registry_id: Dev::Aws::Account.new.ecr_registry_ids.first, region: Dev::Aws::DEFAULT_REGION)
112
+ def docker_login!(registry_id: Dev::Aws::Account.new.ecr_registry_ids.first, region: nil)
113
+ region ||= Dev::Aws::Credentials.new.logged_in_region || Dev::Aws::DEFAULT_REGION
96
114
  warn '[DEPRECATION] `Dev::Aws::Login#docker_login!` is deprecated. Please use `Dev::Aws::Login#registry_login!` instead.'
97
115
  docker_cli_login!(registry: "#{registry_id}.dkr.ecr.#{region}.amazonaws.com", region: region)
98
116
  puts
@@ -110,7 +128,8 @@ module Dev
110
128
 
111
129
  # Authroizes the docker ruby library to pull/push images from the Aws container registry
112
130
  # @deprecated Please use {Dev::Aws::Login#registry_login!} instead
113
- def ecr_login!(registry_id: Dev::Aws::Account.new.ecr_registry_ids.first, region: Dev::Aws::DEFAULT_REGION)
131
+ def ecr_login!(registry_id: Dev::Aws::Account.new.ecr_registry_ids.first, region: nil)
132
+ region ||= Dev::Aws::Credentials.new.logged_in_region || Dev::Aws::DEFAULT_REGION
114
133
  warn '[DEPRECATION] `Dev::Aws::Login#ecr_login!` is deprecated. Please use `Dev::Aws::Login#registry_login!` instead.'
115
134
  docker_lib_login!(registry_id: registry_id, region: region)
116
135
  end
@@ -4,7 +4,10 @@ module Dev
4
4
  # The config dir for the user's AWS settings
5
5
  CONFIG_DIR = "#{Dir.home}/.aws".freeze
6
6
 
7
- # The default region used if none have been configured in the AWS settings
7
+ # The default region used if none has been configured in the AWS settings
8
8
  DEFAULT_REGION = 'us-east-1'.freeze
9
+
10
+ # The default role name used if none has been configured when logging in
11
+ DEFAULT_LOGIN_ROLE_NAME = 'ReadonlyAccessRole'.freeze
9
12
  end
10
13
  end
@@ -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 = '1.4.3'.freeze
9
+ VERSION = '1.5.0.pre.alpha.2'.freeze
10
10
  end
11
11
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: firespring_dev_commands
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.3
4
+ version: 1.5.0.pre.alpha.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Firespring
@@ -453,9 +453,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
453
453
  version: '2.7'
454
454
  required_rubygems_version: !ruby/object:Gem::Requirement
455
455
  requirements:
456
- - - ">="
456
+ - - ">"
457
457
  - !ruby/object:Gem::Version
458
- version: '0'
458
+ version: 1.3.1
459
459
  requirements: []
460
460
  rubygems_version: 3.1.6
461
461
  signing_key: