firespring_dev_commands 1.5.3 → 1.5.4

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: 060f037868598436e3f670ca01a2fdbd3f6bc42148695c7f2b26d1570884d52d
4
- data.tar.gz: 7deeb476f01d1e2dcb1a730c15ebecc529f6d568bbfafaf6e9e7e5333ed14ef9
3
+ metadata.gz: 78decb68edca360ca267232996476a6a1d4e1c2e02ed415bf6efc8c72c1df729
4
+ data.tar.gz: 90c624acb2d76ccb53b61c264d652771f5ae90b8f93bc18df3a0d7f46ee52095
5
5
  SHA512:
6
- metadata.gz: a30f757615b686dca3c7c6fca8b2f5b034a2591c4fd6ce86f149a75351c473fa09da301fc10cb5fba014f332e6aacc22170cd6be768e0101095293865fd226fe
7
- data.tar.gz: 939a251e7bfd47ee62af90838ba8e6eaa4d334ca05b2462ba4605c9314e1e6d29fc176f8d7e978923a3ca6385d4571cf5ab8ce431075f23973784b401ae6563f
6
+ metadata.gz: 1f8ccdbcb9994d2be9c7140c083711f28f40f2451e2d1adfb3ca17feefd93896014d991b8870d5d88bb2a775fac6900fc24977cf7077aa343a366761844612e1
7
+ data.tar.gz: f61c95e4317077e6a3384e9e6fbdc850a57e0e99739f17cfd6e1d7145376b4c837318c7e861f559b1c779de782d1fd0bec95f7179afd7c4cdf855c93aeb0da4c
@@ -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
@@ -0,0 +1,32 @@
1
+ # Load any existing slack auth if we haven't set one in the environment
2
+ require 'dotenv'
3
+
4
+ module Dev
5
+ class Slack
6
+ class Global
7
+ # The filename where we store the local auth information
8
+ CONFIG_FILE = "#{Dir.home}/.env.slack".freeze
9
+
10
+ SLACK_API_TOKEN = 'SLACK_API_TOKEN'.freeze
11
+
12
+ def configure
13
+ # Always load the env slack auth
14
+ Dotenv.load(CONFIG_FILE) if File.exist?(CONFIG_FILE)
15
+
16
+ ::Slack.configure do |c|
17
+ c.token = ENV.fetch('SLACK_API_TOKEN', nil)
18
+ c.logger = LOG if ENV['ENABLE_SLACK_DEBUG'].to_s.strip == 'true'
19
+ end
20
+ end
21
+ new.configure
22
+
23
+ # Write the new slack auth value to the env file
24
+ def write!(api_token)
25
+ override = Dev::Env.new(CONFIG_FILE)
26
+ override.set(SLACK_API_TOKEN, api_token)
27
+ override.write
28
+ configure
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,23 @@
1
+ require 'slack'
2
+
3
+ module Dev
4
+ class Slack
5
+ attr_accessor :client
6
+
7
+ def initialize
8
+ @client = ::Slack::Web::Client.new
9
+ @client.auth_test
10
+ end
11
+
12
+ def post(channel:, text:)
13
+ client.chat_postMessage(channel: channel, text: text)
14
+ end
15
+
16
+ def upload_text(channel:, text:, title: 'Text File', filename: 'file.txt')
17
+ raise 'text should be a string' unless text.is_a?(String)
18
+
19
+ file = Faraday::UploadIO.new(StringIO.new(text), 'text/plain')
20
+ client.files_upload(channels: channel, title: title, file: file, filename: filename, filetype: 'text')
21
+ end
22
+ end
23
+ 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.5.3'.freeze
9
+ VERSION = '1.5.4'.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.3
4
+ version: 1.5.4
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-10 00:00:00.000000000 Z
11
+ date: 2023-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -234,6 +234,20 @@ dependencies:
234
234
  - - "~>"
235
235
  - !ruby/object:Gem::Version
236
236
  version: 13.0.0
237
+ - !ruby/object:Gem::Dependency
238
+ name: slack-ruby-client
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - "~>"
242
+ - !ruby/object:Gem::Version
243
+ version: 2.1.0
244
+ type: :runtime
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - "~>"
249
+ - !ruby/object:Gem::Version
250
+ version: 2.1.0
237
251
  - !ruby/object:Gem::Dependency
238
252
  name: builder
239
253
  requirement: !ruby/object:Gem::Requirement
@@ -423,6 +437,8 @@ files:
423
437
  - lib/firespring_dev_commands/ruby.rb
424
438
  - lib/firespring_dev_commands/ruby/audit.rb
425
439
  - lib/firespring_dev_commands/second.rb
440
+ - lib/firespring_dev_commands/slack.rb
441
+ - lib/firespring_dev_commands/slack/global.rb
426
442
  - lib/firespring_dev_commands/tar.rb
427
443
  - lib/firespring_dev_commands/tar/pax_header.rb
428
444
  - lib/firespring_dev_commands/tar/type_flag.rb