firespring_dev_commands 1.4.2.pre.alpha.2 → 1.5.0.pre.alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/firespring_dev_commands/aws/account.rb +17 -7
- data/lib/firespring_dev_commands/aws/credentials.rb +2 -10
- data/lib/firespring_dev_commands/aws/login.rb +30 -12
- data/lib/firespring_dev_commands/aws/profile.rb +1 -3
- data/lib/firespring_dev_commands/aws.rb +4 -1
- data/lib/firespring_dev_commands/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea3652c102b7a6ec3395c7b524db518655b574a6050d8f740f2c20daedf63aed
|
4
|
+
data.tar.gz: 162e4aa151f14b901b7fcfea1c2b8e3cb1b20ab3de2d9102d00a35b0754e5773
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 724282fb3154de07595863a899f29b1ffeea0e5fda1d3d2aa5fb31fd3e17f57bfbc0e9baaf534c4a0e259b8b95b051ba05b6d7072d1cdd4bc544799f665e519a
|
7
|
+
data.tar.gz: b60bf002f396a052f0814838940dcb441d95c263a4001bdbdcd18878d0d1a8ee0b7f1a8b5b4026ce43664a92666ab93b23a27e0d9d765669f827171c377d4d3d
|
data/README.md
CHANGED
@@ -11,7 +11,7 @@ gem 'firespring_dev_commands', '~> 0.0.1'
|
|
11
11
|
* This is not common
|
12
12
|
* It is mostly used for testing local changes before the gem is released
|
13
13
|
```
|
14
|
-
gem 'firespring_dev_commands', path: '/path/to/
|
14
|
+
gem 'firespring_dev_commands', path: '/path/to/dev_commands'
|
15
15
|
```
|
16
16
|
|
17
17
|
* Add the following to your Rakefile
|
@@ -3,13 +3,13 @@ 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)
|
6
|
+
Config = Struct.new(:root, :children, :default, :registry, :default_login_role_name)
|
7
7
|
|
8
8
|
# Instantiates a new top level config object if one hasn't already been created
|
9
9
|
# Yields that config object to any given block
|
10
10
|
# Returns the resulting config object
|
11
11
|
def self.config
|
12
|
-
@config ||= Config.new
|
12
|
+
@config ||= Config.new(default_login_role_name: Dev::Aws::DEFAULT_LOGIN_ROLE_NAME)
|
13
13
|
yield(@config) if block_given?
|
14
14
|
@config
|
15
15
|
end
|
@@ -55,7 +55,7 @@ module Dev
|
|
55
55
|
|
56
56
|
# Look up the account name for the given account id
|
57
57
|
def name_by_account(account)
|
58
|
-
all.find { |it| it.id == account }
|
58
|
+
all.find { |it| it.id == account }.name
|
59
59
|
end
|
60
60
|
|
61
61
|
# Setup base Aws settings
|
@@ -73,8 +73,13 @@ module Dev
|
|
73
73
|
region_default = defaultini['region'] || ENV['AWS_DEFAULT_REGION'] || Dev::Aws::DEFAULT_REGION
|
74
74
|
defaultini['region'] = Dev::Common.new.ask('Default region name', region_default)
|
75
75
|
|
76
|
-
|
77
|
-
|
76
|
+
# NOTE: We had an old config for "mfa_serial" which included the entire arn. We deprecated that config since
|
77
|
+
# it made it much more difficult to switch between different root accounts.
|
78
|
+
mfa_name_default = defaultini['mfa_serial']&.split(%r{mfa/})&.last || ENV['AWS_MFA_ARN']&.split(%r{mfa/})&.last || ENV.fetch('USERNAME', nil)
|
79
|
+
defaultini['mfa_serial_name'] = Dev::Common.new.ask('Default mfa name', mfa_name_default)
|
80
|
+
# TODO: Eventually, we should delete the mfa_serial entry from the config. Leaving it for now because some projects
|
81
|
+
# may be using older versions of the dev_commands library
|
82
|
+
# defaultini.delete('mfa_serial')
|
78
83
|
|
79
84
|
session_name_default = defaultini['role_session_name'] || "#{ENV.fetch('USERNAME', nil)}_cli"
|
80
85
|
defaultini['role_session_name'] = Dev::Common.new.ask('Default session name', session_name_default)
|
@@ -111,8 +116,13 @@ module Dev
|
|
111
116
|
region_default = profileini['region'] || defaultini['region'] || ENV['AWS_DEFAULT_REGION'] || Dev::Aws::DEFAULT_REGION
|
112
117
|
profileini['region'] = Dev::Common.new.ask('Default region name', region_default)
|
113
118
|
|
114
|
-
|
115
|
-
|
119
|
+
# NOTE: We had an old config for "role_arn" which included the entire arn. We deprecated that config since
|
120
|
+
# it made it much more difficult to switch between different accounts.
|
121
|
+
role_name_default = profileini['role_name'] || profileini['role_arn']&.split(%r{role/})&.last || self.class.config.default_login_role_name
|
122
|
+
profileini['role_name'] = Dev::Common.new.ask('Default role name', role_name_default)
|
123
|
+
# TODO: Eventually, we should delete the role_arn entry from the config. Leaving it for now because some projects
|
124
|
+
# may be using older versions of the dev_commands library
|
125
|
+
# profileini.delete('role_arn')
|
116
126
|
|
117
127
|
cfgini.write
|
118
128
|
end
|
@@ -16,16 +16,6 @@ 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
|
-
|
29
19
|
# The region associated with the current login
|
30
20
|
def logged_in_region
|
31
21
|
::Aws::STS::Client.new.send(:config).region
|
@@ -75,6 +65,8 @@ module Dev
|
|
75
65
|
credini = IniFile.new(filename: "#{Dev::Aws::CONFIG_DIR}/credentials", default: 'default')
|
76
66
|
defaultini = credini['default']
|
77
67
|
|
68
|
+
# TODO: Should we allow for multiple sets of base credentials? How do I use this for both FDP and SBF?
|
69
|
+
|
78
70
|
access_key_default = defaultini['aws_access_key_id']
|
79
71
|
defaultini['aws_access_key_id'] = Dev::Common.new.ask('AWS Access Key ID', access_key_default)
|
80
72
|
|
@@ -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 =
|
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
|
-
|
44
|
-
|
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_login!(registry_id: Dev::Aws::Account.new.registry, region:
|
85
|
+
def registry_login!(registry_id: Dev::Aws::Account.new.registry, region: nil)
|
86
|
+
region ||= Dev::Aws::Credentials.new.logged_in_region || Dev::Aws::DEFAULT_REGION
|
71
87
|
raise 'registry_id is required' if registry_id.to_s.strip.empty?
|
72
88
|
raise 'region is required' if region.to_s.strip.empty?
|
73
89
|
|
@@ -82,7 +98,8 @@ module Dev
|
|
82
98
|
# Authroizes the docker cli to pull/push images from the Aws container registry
|
83
99
|
# (e.g. if docker compose needs to pull an image)
|
84
100
|
# @deprecated Please use {Dev::Aws::Login#registry_login!} instead
|
85
|
-
def docker_login!(registry_id: Dev::Aws::Account.new.registry, region:
|
101
|
+
def docker_login!(registry_id: Dev::Aws::Account.new.registry, region: nil)
|
102
|
+
region ||= Dev::Aws::Credentials.new.logged_in_region || Dev::Aws::DEFAULT_REGION
|
86
103
|
warn '[DEPRECATION] `Dev::Aws::Login#docker_login!` is deprecated. Please use `Dev::Aws::Login#registry_login!` instead.'
|
87
104
|
docker_cli_login!(registry: "#{registry_id}.dkr.ecr.#{region}.amazonaws.com", region: region)
|
88
105
|
end
|
@@ -100,7 +117,8 @@ module Dev
|
|
100
117
|
|
101
118
|
# Authroizes the docker ruby library to pull/push images from the Aws container registry
|
102
119
|
# @deprecated Please use {Dev::Aws::Login#registry_login!} instead
|
103
|
-
def ecr_login!(registry_id: Dev::Aws::Account.new.registry, region:
|
120
|
+
def ecr_login!(registry_id: Dev::Aws::Account.new.registry, region: nil)
|
121
|
+
region ||= Dev::Aws::Credentials.new.logged_in_region || Dev::Aws::DEFAULT_REGION
|
104
122
|
warn '[DEPRECATION] `Dev::Aws::Login#ecr_login!` is deprecated. Please use `Dev::Aws::Login#registry_login!` instead.'
|
105
123
|
docker_lib_login!(registry_id: registry_id, region: region)
|
106
124
|
end
|
@@ -33,10 +33,8 @@ 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)
|
38
36
|
puts
|
39
|
-
puts " Currently logged in
|
37
|
+
puts " Currently logged in to the #{Dev::Aws::Account.new.name_by_account(current)} (#{current})".light_yellow
|
40
38
|
puts
|
41
39
|
puts ' To use this profile in your local aws cli, you must either pass the profile as a command line argument ' \
|
42
40
|
'or export the corresponding aws variable:'.light_white
|
@@ -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
|
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
|
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.
|
4
|
+
version: 1.5.0.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: 2023-05-
|
11
|
+
date: 2023-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|