firespring_dev_commands 2.0.5 → 2.1.1.pre.alpha.1

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: 3f226b6a68359f106c098bb36e5904e0cd0000452efe9f865c8db1cb272c44f3
4
- data.tar.gz: 4f2e2cfe51f2da74ad2d2d3af0cf1ae7cb293878081ea918098508bba6bcbb61
3
+ metadata.gz: a503e80f6ca42a9310361f9ecff5d1977eacaba76043acc678366af991b3a35c
4
+ data.tar.gz: 19cb2cabecd31b198de46bfbed9210954a9a733eaae49f16c43bf81ff3b58d1e
5
5
  SHA512:
6
- metadata.gz: 8b0bf1baed137fa76c7c2970a4c4f5133c334b5f56dea14b6ef886664a77200232980d6461a56750e716c40198fb0517914c1e9e84664523598de1354d59730e
7
- data.tar.gz: 2feb5e0133dcdc77eec4031d724f4c07a0d30e51f05e91aa62200b3a0e386efe41b84b1ccafe472648f77fbf9889b4c185fb65884345c5cff81a01b1c1163b23
6
+ metadata.gz: e2d32d0d9fbd06bff8a89b528ffb5e07ac814178c4c76036033ef62442ce6b99135951b02a8827cbe75e14adee439b2f2ddde456858d19118af14a7f8939465f
7
+ data.tar.gz: ab03be7074cb9aa64f29d0f177082b0a09cfff717790c83469fb23c1bcb047f6deaee131c94e39673bc0599692b9887edd4208c7a0385a930a460d0c4fa7832c
@@ -10,7 +10,7 @@ module Dev
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({default_login_role_name: Dev::Aws::DEFAULT_LOGIN_ROLE_NAME})
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
@@ -23,6 +23,10 @@ module Dev
23
23
  # The name of the file containing the Aws settings
24
24
  CONFIG_FILE = "#{Dev::Aws::CONFIG_DIR}/config".freeze
25
25
 
26
+ def self.config_ini
27
+ IniFile.new(filename: CONFIG_FILE, default: 'default')
28
+ end
29
+
26
30
  # TODO: registry is deprecated and should be removed on the next major release
27
31
  attr_accessor :root, :children, :default, :registry, :ecr_registry_ids
28
32
 
@@ -75,7 +79,7 @@ module Dev
75
79
  puts 'Configuring default login values'
76
80
 
77
81
  # Write region and mfa serial to config file
78
- cfgini = IniFile.new(filename: "#{Dev::Aws::CONFIG_DIR}/config", default: 'default')
82
+ cfgini = self.class.config_ini
79
83
  defaultini = cfgini['default']
80
84
 
81
85
  region_default = defaultini['region'] || ENV['AWS_DEFAULT_REGION'] || Dev::Aws::DEFAULT_REGION
@@ -101,7 +105,7 @@ module Dev
101
105
  # Setup Aws account specific settings
102
106
  def setup!(account)
103
107
  # Run base setup if it doesn't exist
104
- Rake::Task['aws:configure:default'].invoke unless File.exist?(CONFIG_FILE)
108
+ Rake::Task['aws:configure:default'].invoke unless File.exist?(CONFIG_FILE) && self.class.config_ini.has_section?('default')
105
109
 
106
110
  puts
107
111
  puts "Configuring #{account} login values"
@@ -115,7 +119,7 @@ module Dev
115
119
  raise 'Configure default account settings first (rake aws:configure:default)' unless File.exist?(CONFIG_FILE)
116
120
 
117
121
  # Parse the ini file and load values
118
- cfgini = IniFile.new(filename: CONFIG_FILE, default: 'default')
122
+ cfgini = self.class.config_ini
119
123
  defaultini = cfgini['default']
120
124
  profileini = cfgini["profile #{account}"]
121
125
 
@@ -124,13 +128,21 @@ module Dev
124
128
  region_default = profileini['region'] || defaultini['region'] || ENV['AWS_DEFAULT_REGION'] || Dev::Aws::DEFAULT_REGION
125
129
  profileini['region'] = Dev::Common.new.ask('Default region name', region_default)
126
130
 
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: role_arn is deprecated. Eventually, we should delete the role_arn entry from the config. Leaving it for now
131
+ # NOTE: Turns out the role_arn is needed by the aws cli so we are changing directions here. Eventually we should remove the role_name
132
+ # from the ini files and only store the role arn. However we need to still keep the functinoality so that the user is only asked
133
+ # for the role name - not the entire arn
134
+ role_name_default = if profileini['role_name']
135
+ profileini['role_name']
136
+ elsif profileini['role_arn']
137
+ profileini['role_arn']&.split(%r{role/})&.last
138
+ else
139
+ self.class.config.default_login_role_name
140
+ end
141
+ role_name = Dev::Common.new.ask('Default role name', role_name_default)
142
+ profileini['role_arn'] = "arn:aws:iam::#{account}:role/#{role_name}"
143
+ # TODO: role_name is deprecated. Eventually, we should delete the role_name entry from the config. Leaving it for now
132
144
  # because some projects may be using older versions of the dev_commands library
133
- # profileini.delete('role_arn')
145
+ # profileini.delete('role_name')
134
146
 
135
147
  cfgini.write
136
148
  end
@@ -11,6 +11,10 @@ module Dev
11
11
  # The local file where temporary credentials are stored
12
12
  CONFIG_FILE = "#{Dev::Aws::CONFIG_DIR}/credentials".freeze
13
13
 
14
+ def self.config_ini
15
+ IniFile.new(filename: CONFIG_FILE, default: 'default')
16
+ end
17
+
14
18
  # The account the profile is currently logged in to
15
19
  def logged_in_account
16
20
  ::Aws::STS::Client.new.get_caller_identity.account
@@ -72,7 +76,7 @@ module Dev
72
76
  puts 'Configuring default credential values'
73
77
 
74
78
  # Write access key / secret key in the credentials file
75
- credini = IniFile.new(filename: "#{Dev::Aws::CONFIG_DIR}/credentials", default: 'default')
79
+ credini = self.class.config_ini
76
80
  defaultini = credini['default']
77
81
 
78
82
  access_key_default = defaultini['aws_access_key_id']
@@ -87,7 +91,7 @@ module Dev
87
91
  # Write Aws account specific settings to the credentials file
88
92
  def write!(account, creds)
89
93
  # Write access key / secret key / session token in the credentials file
90
- credini = IniFile.new(filename: CONFIG_FILE, default: 'default')
94
+ credini = self.class.config_ini
91
95
  defaultini = credini[account]
92
96
 
93
97
  defaultini['aws_access_key_id'] = creds.access_key_id
@@ -132,7 +136,7 @@ module Dev
132
136
  return unless File.exist?(CONFIG_FILE)
133
137
 
134
138
  # Otherwise load access key / secret key / session token from the credentials file into the environment
135
- credini = IniFile.new(filename: CONFIG_FILE, default: 'default')
139
+ credini = self.class.config_ini
136
140
  profile_credentials = credini[Dev::Aws::Profile.new.current]
137
141
  return unless profile_credentials
138
142
 
@@ -42,9 +42,11 @@ module Dev
42
42
  serial = "arn:aws:iam::#{Dev::Aws::Account.new.root.id}:mfa/#{serial}" if serial
43
43
  serial ||= profileini['mfa_serial'] || defaultini['mfa_serial']
44
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']
45
+ role = profileini['role_arn'] || defaultini['role_arn']
46
+ # NOTE: We supported role name for a period of time but we are switching back to role_arn.
47
+ # Leaving this here for a period of time until it can be deprecated
48
+ role ||= "arn:aws:iam::#{account}:role/#{profileini['role_name'] || defaultini['role_name']}"
49
+ # TODO: role_name is deprecated. Eventually, we should remove the above line
48
50
 
49
51
  session_name = profileini['role_session_name'] || defaultini['role_session_name']
50
52
  session_duration = profileini['session_duration'] || defaultini['session_duration']
@@ -72,10 +74,10 @@ module Dev
72
74
  # Returns the config ini file
73
75
  # Runs the setup for our current account if it's not already setup
74
76
  def setup_cfgini(account)
75
- cfgini = IniFile.new(filename: "#{Dev::Aws::CONFIG_DIR}/config", default: 'default')
77
+ cfgini = Dev::Aws::Account.config_ini
76
78
  unless cfgini.has_section?("profile #{account}")
77
79
  Dev::Aws::Account.new.write!(account)
78
- cfgini = IniFile.new(filename: "#{Dev::Aws::CONFIG_DIR}/config", default: 'default')
80
+ cfgini = Dev::Aws::Account.config_ini
79
81
  end
80
82
  cfgini
81
83
  end
@@ -7,13 +7,7 @@ module Dev
7
7
  attr_accessor :client
8
8
 
9
9
  def initialize
10
- @client = nil
11
- end
12
-
13
- # Create/set a new client if none is present
14
- # Return the client
15
- def client
16
- @client ||= ::Aws::SSM::Client.new
10
+ @client = ::Aws::SSM::Client.new
17
11
  end
18
12
 
19
13
  # Get the value of the given parameter name
@@ -27,6 +21,32 @@ module Dev
27
21
  rescue ::Aws::SSM::Errors::ParameterNotFound
28
22
  raise "parameter #{name} does not exist in #{Dev::Aws::Profile.new.current}"
29
23
  end
24
+
25
+ # Retrieve all parameters which start with the given path
26
+ def list(path, recursive: true, with_decryption: true)
27
+ next_token = nil
28
+
29
+ parameters = []
30
+ loop do
31
+ response = client.get_parameters_by_path(
32
+ path:,
33
+ recursive:,
34
+ with_decryption:,
35
+ next_token:
36
+ )
37
+ parameters += response.parameters
38
+ break unless (next_token = response.next_token)
39
+ end
40
+ parameters
41
+ end
42
+
43
+ # Sets the given parameter name's value to the given value
44
+ # Pass in additional params as desired
45
+ def put(name, value, **params)
46
+ params[:type] ||= 'String'
47
+ params[:overwrite] ||= true
48
+ client.put_parameter(name:, value:, **params)
49
+ end
30
50
  end
31
51
  end
32
52
  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 = '2.0.5'.freeze
9
+ VERSION = '2.1.1.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.0.5
4
+ version: 2.1.1.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-07-20 00:00:00.000000000 Z
11
+ date: 2023-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -329,9 +329,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
329
329
  version: '3.1'
330
330
  required_rubygems_version: !ruby/object:Gem::Requirement
331
331
  requirements:
332
- - - ">="
332
+ - - ">"
333
333
  - !ruby/object:Gem::Version
334
- version: '0'
334
+ version: 1.3.1
335
335
  requirements: []
336
336
  rubygems_version: 3.4.10
337
337
  signing_key: