firespring_dev_commands 1.5.0.pre.alpha.1 → 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: ea3652c102b7a6ec3395c7b524db518655b574a6050d8f740f2c20daedf63aed
4
- data.tar.gz: 162e4aa151f14b901b7fcfea1c2b8e3cb1b20ab3de2d9102d00a35b0754e5773
3
+ metadata.gz: c00aad2781f73b860860758fa26f0976413ec9917c472a702e4dc93caeffe725
4
+ data.tar.gz: bad9dce8ab37b9e3a71ba479f05fd23405c0ab91abad53ef1f57f2b5f7daf073
5
5
  SHA512:
6
- metadata.gz: 724282fb3154de07595863a899f29b1ffeea0e5fda1d3d2aa5fb31fd3e17f57bfbc0e9baaf534c4a0e259b8b95b051ba05b6d7072d1cdd4bc544799f665e519a
7
- data.tar.gz: b60bf002f396a052f0814838940dcb441d95c263a4001bdbdcd18878d0d1a8ee0b7f1a8b5b4026ce43664a92666ab93b23a27e0d9d765669f827171c377d4d3d
6
+ metadata.gz: 1818bc0df7bc48e264a95b4a091e0b02776ae9e5fb3f56a06b6e2d39d0bf6aa9ca3275a9af6aba06bd62a139c999951a18fd9859a41601910d6bc986680be4bc
7
+ data.tar.gz: 3259dd964ab887e049166cba3552e3cdc87f9b9e67170acc48363daf3f1495543fd691dbd5be51c63d3cbe44c15ecebbc784f5f4df826fcec452bbbb06caedc8
@@ -3,7 +3,8 @@ module Dev
3
3
  # Class containing useful methods for interacting with the Aws account
4
4
  class Account
5
5
  # Config object for setting top level Aws account config options
6
- Config = Struct.new(:root, :children, :default, :registry, :default_login_role_name)
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, :default_login_role_name)
7
8
 
8
9
  # Instantiates a new top level config object if one hasn't already been created
9
10
  # Yields that config object to any given block
@@ -22,7 +23,8 @@ module Dev
22
23
  # The name of the file containing the Aws settings
23
24
  CONFIG_FILE = "#{Dev::Aws::CONFIG_DIR}/config".freeze
24
25
 
25
- attr_accessor :root, :children, :default, :registry
26
+ # TODO: registry is deprecated and should be removed on the next major release
27
+ attr_accessor :root, :children, :default, :registry, :ecr_registry_ids
26
28
 
27
29
  # Instantiate an account object
28
30
  # Requires that root account and at least one child account have been configured
@@ -35,7 +37,13 @@ module Dev
35
37
  @root = self.class.config.root
36
38
  @children = self.class.config.children
37
39
  @default = self.class.config.default
38
- @registry = self.class.config.registry
40
+
41
+ # Create the ecr registry list based off several possible configuration values
42
+ @ecr_registry_ids = [self.class.config.registry]
43
+ @ecr_registry_ids << Dev::Aws::Profile.new.current if self.class.config.login_to_account_ecr_registry
44
+ @ecr_registry_ids.concat(Array(self.class.config.ecr_registry_ids))
45
+ @ecr_registry_ids = @ecr_registry_ids.flatten.compact.reject(&:empty?).uniq
46
+ @registry = @ecr_registry_ids.first
39
47
  end
40
48
 
41
49
  # Returns all configured account information objects
@@ -55,7 +63,7 @@ module Dev
55
63
 
56
64
  # Look up the account name for the given account id
57
65
  def name_by_account(account)
58
- all.find { |it| it.id == account }.name
66
+ all.find { |it| it.id == account }&.name
59
67
  end
60
68
 
61
69
  # Setup base Aws settings
@@ -16,6 +16,16 @@ module Dev
16
16
  ::Aws::STS::Client.new.get_caller_identity.account
17
17
  end
18
18
 
19
+ # The arn of the currently logged in identity
20
+ def logged_in_arn
21
+ ::Aws::STS::Client.new.get_caller_identity.arn
22
+ end
23
+
24
+ # The role the current identity is using
25
+ def logged_in_role
26
+ logged_in_arn.split(%r{/})[1]
27
+ end
28
+
19
29
  # The region associated with the current login
20
30
  def logged_in_region
21
31
  ::Aws::STS::Client.new.send(:config).region
@@ -8,7 +8,7 @@ module Dev
8
8
  class Login
9
9
  # Main interface for logging in to an AWS account
10
10
  # If an account is not specified the user is given an account selection menu
11
- # If an account registry has been configured, the user is also logged in to the docker registry
11
+ # If account registries have been configured, the user is also logged in to the docker registries
12
12
  def login!(account = nil)
13
13
  # If more than one child account has been configured, have the user select the account they want to log in to
14
14
  account ||= Dev::Aws::Account.new.select
@@ -22,8 +22,8 @@ module Dev
22
22
  # Load credentials into the ENV for subprocesses
23
23
  Dev::Aws::Credentials.new.export!
24
24
 
25
- # Login in to the docker registry if the user has configured one
26
- registry_login! if Dev::Aws::Account.new.registry
25
+ # Login in to all configured docker registries
26
+ registry_logins!
27
27
  end
28
28
 
29
29
  # Authorize your local credentials
@@ -82,7 +82,18 @@ module Dev
82
82
 
83
83
  # Authroizes the docker cli to pull/push images from the Aws container registry (e.g. if docker compose needs to pull an image)
84
84
  # Authroizes the docker ruby library to pull/push images from the Aws container registry
85
- def registry_login!(registry_id: Dev::Aws::Account.new.registry, region: nil)
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
87
+ return if registry_ids.empty?
88
+
89
+ puts
90
+ registry_ids.each { |id| registry_login!(registry_id: id, region: region) }
91
+ puts
92
+ end
93
+
94
+ # Authroizes the docker cli to pull/push images from the Aws container registry (e.g. if docker compose needs to pull an image)
95
+ # Authroizes the docker ruby library to pull/push images from the Aws container registry
96
+ def registry_login!(registry_id: Dev::Aws::Account.new.ecr_registry_ids.first, region: nil)
86
97
  region ||= Dev::Aws::Credentials.new.logged_in_region || Dev::Aws::DEFAULT_REGION
87
98
  raise 'registry_id is required' if registry_id.to_s.strip.empty?
88
99
  raise 'region is required' if region.to_s.strip.empty?
@@ -98,26 +109,26 @@ module Dev
98
109
  # Authroizes the docker cli to pull/push images from the Aws container registry
99
110
  # (e.g. if docker compose needs to pull an image)
100
111
  # @deprecated Please use {Dev::Aws::Login#registry_login!} instead
101
- def docker_login!(registry_id: Dev::Aws::Account.new.registry, region: nil)
112
+ def docker_login!(registry_id: Dev::Aws::Account.new.ecr_registry_ids.first, region: nil)
102
113
  region ||= Dev::Aws::Credentials.new.logged_in_region || Dev::Aws::DEFAULT_REGION
103
114
  warn '[DEPRECATION] `Dev::Aws::Login#docker_login!` is deprecated. Please use `Dev::Aws::Login#registry_login!` instead.'
104
115
  docker_cli_login!(registry: "#{registry_id}.dkr.ecr.#{region}.amazonaws.com", region: region)
116
+ puts
105
117
  end
106
118
 
107
119
  # Authroizes the docker cli to pull/push images from the Aws container registry
108
120
  # (e.g. if docker compose needs to pull an image)
109
121
  private def docker_cli_login!(registry:, region:)
110
- print(' Logging in to ECR in docker... ')
122
+ print(" Logging in to #{registry} in docker... ")
111
123
  login_cmd = "aws --profile=#{Dev::Aws::Profile.new.current} ecr --region=#{region} get-login-password"
112
124
  login_cmd << ' | '
113
125
  login_cmd << "docker login --password-stdin --username AWS #{registry}"
114
126
  Dev::Common.new.run_command([login_cmd])
115
- puts
116
127
  end
117
128
 
118
129
  # Authroizes the docker ruby library to pull/push images from the Aws container registry
119
130
  # @deprecated Please use {Dev::Aws::Login#registry_login!} instead
120
- def ecr_login!(registry_id: Dev::Aws::Account.new.registry, region: nil)
131
+ def ecr_login!(registry_id: Dev::Aws::Account.new.ecr_registry_ids.first, region: nil)
121
132
  region ||= Dev::Aws::Credentials.new.logged_in_region || Dev::Aws::DEFAULT_REGION
122
133
  warn '[DEPRECATION] `Dev::Aws::Login#ecr_login!` is deprecated. Please use `Dev::Aws::Login#registry_login!` instead.'
123
134
  docker_lib_login!(registry_id: registry_id, region: region)
@@ -33,8 +33,10 @@ module Dev
33
33
  # Print the profile info for the current account
34
34
  def info
35
35
  Dev::Aws::Credentials.new.export!
36
+ current_role = Dev::Aws::Credentials.new.logged_in_role
37
+ current_account_name = Dev::Aws::Account.new.name_by_account(current)
36
38
  puts
37
- puts " Currently logged in to the #{Dev::Aws::Account.new.name_by_account(current)} (#{current})".light_yellow
39
+ puts " Currently logged in as #{current_role} in the #{current_account_name} (#{current}) account".light_yellow
38
40
  puts
39
41
  puts ' To use this profile in your local aws cli, you must either pass the profile as a command line argument ' \
40
42
  'or export the corresponding aws variable:'.light_white
@@ -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.5.0.pre.alpha.1'.freeze
9
+ VERSION = '1.5.0.pre.alpha.2'.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: 1.5.0.pre.alpha.1
4
+ version: 1.5.0.pre.alpha.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Firespring
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-09 00:00:00.000000000 Z
11
+ date: 2023-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport