firespring_dev_commands 1.5.3.pre.alpha.1 → 1.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/firespring_dev_commands/aws/account.rb +21 -9
- data/lib/firespring_dev_commands/aws/credentials.rb +7 -3
- data/lib/firespring_dev_commands/aws/login.rb +7 -5
- data/lib/firespring_dev_commands/docker/compose.rb +6 -15
- data/lib/firespring_dev_commands/docker.rb +6 -1
- data/lib/firespring_dev_commands/slack/global.rb +32 -0
- data/lib/firespring_dev_commands/slack.rb +23 -0
- data/lib/firespring_dev_commands/version.rb +1 -1
- metadata +20 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78decb68edca360ca267232996476a6a1d4e1c2e02ed415bf6efc8c72c1df729
|
4
|
+
data.tar.gz: 90c624acb2d76ccb53b61c264d652771f5ae90b8f93bc18df3a0d7f46ee52095
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 =
|
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 =
|
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:
|
128
|
-
#
|
129
|
-
|
130
|
-
profileini['role_name']
|
131
|
-
|
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('
|
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 =
|
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 =
|
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 =
|
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['
|
46
|
-
|
47
|
-
|
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 =
|
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 =
|
80
|
+
cfgini = Dev::Aws::Account.config_ini
|
79
81
|
end
|
80
82
|
cfgini
|
81
83
|
end
|
@@ -8,9 +8,8 @@ module Dev
|
|
8
8
|
# Class containing methods for interfacing with the docker compose cli
|
9
9
|
class Compose
|
10
10
|
# Config object for setting top level docker compose config options
|
11
|
-
Config = Struct.new(:
|
11
|
+
Config = Struct.new(:project_dir, :project_name, :compose_files, :min_version, :max_version) do
|
12
12
|
def initialize
|
13
|
-
self.executable_name = EXECUTABLE_NAME
|
14
13
|
self.project_dir = DEV_COMMANDS_ROOT_DIR
|
15
14
|
self.project_name = DEV_COMMANDS_PROJECT_NAME
|
16
15
|
self.compose_files = ["#{DEV_COMMANDS_ROOT_DIR}/docker-compose.yml"]
|
@@ -70,12 +69,12 @@ module Dev
|
|
70
69
|
# Checks the min and max version against the current docker version if they have been configured
|
71
70
|
def check_version
|
72
71
|
min_version = self.class.config.min_version
|
73
|
-
|
74
|
-
|
72
|
+
raise "requires #{EXECUTABLE_NAME} version >= #{min_version} (found #{self.class.version})" if min_version &&
|
73
|
+
!Dev::Common.new.version_greater_than(min_version, self.class.version)
|
75
74
|
|
76
75
|
max_version = self.class.config.max_version
|
77
|
-
|
78
|
-
|
76
|
+
raise "requires #{EXECUTABLE_NAME} version < #{max_version} (found #{self.class.version})" if max_version &&
|
77
|
+
Dev::Common.new.version_greater_than(max_version, self.class.version)
|
79
78
|
end
|
80
79
|
|
81
80
|
# Pull in supported env settings and call build
|
@@ -84,7 +83,6 @@ module Dev
|
|
84
83
|
def build
|
85
84
|
merge_options('--parallel')
|
86
85
|
merge_env_pull_option
|
87
|
-
merge_env_push_option
|
88
86
|
merge_env_cache_option
|
89
87
|
execute_command(build_command('build'))
|
90
88
|
end
|
@@ -183,13 +181,6 @@ module Dev
|
|
183
181
|
merge_options('--pull') if ENV['PULL'].to_s.strip == 'true'
|
184
182
|
end
|
185
183
|
|
186
|
-
# Merge --push option if PUSH is set to true and no existing push options are present
|
187
|
-
private def merge_env_push_option
|
188
|
-
return if @options.any? { |it| it.include?('push') }
|
189
|
-
|
190
|
-
merge_options('--push') if ENV['PUSH'].to_s.strip == 'true'
|
191
|
-
end
|
192
|
-
|
193
184
|
# Merge --no-build option unless BUILD is set to true and no existing build options are present
|
194
185
|
private def merge_env_build_option
|
195
186
|
return if @options.any? { |it| it.include?('build') }
|
@@ -239,7 +230,7 @@ module Dev
|
|
239
230
|
|
240
231
|
# Build the compose command with the given inputs
|
241
232
|
private def build_command(action, *cmd)
|
242
|
-
command =
|
233
|
+
command = [EXECUTABLE_NAME]
|
243
234
|
command << '--project-directory' << project_dir
|
244
235
|
command << '-p' << project_name if project_name
|
245
236
|
Array(compose_files).compact.each { |file| command << '-f' << file }
|
@@ -201,6 +201,8 @@ module Dev
|
|
201
201
|
private def image_info(image)
|
202
202
|
[].tap do |ary|
|
203
203
|
arch = image.json&.dig('Architecture')
|
204
|
+
variant = image.json&.dig('Variant')
|
205
|
+
arch = "#{arch}/#{variant}" if variant
|
204
206
|
id = image.info&.dig('id')&.split(':')&.last&.slice(0..11)
|
205
207
|
created = timesince(Time.at(image.info&.dig('Created')))
|
206
208
|
size = filesize(image.info&.dig('Size'))
|
@@ -253,7 +255,10 @@ module Dev
|
|
253
255
|
private def container_info(container)
|
254
256
|
id = container.id&.slice(0..11)
|
255
257
|
image = container.info&.dig('Image')
|
256
|
-
|
258
|
+
image_json = ::Docker::Image.get(image).json
|
259
|
+
arch = image_json&.dig('Architecture')
|
260
|
+
variant = image_json&.dig('Variant')
|
261
|
+
arch = "#{arch}/#{variant}" if variant
|
257
262
|
command = container.info&.dig('Command')
|
258
263
|
created = timesince(Time.at(container.info&.dig('Created')))
|
259
264
|
status = container.info&.dig('Status')
|
@@ -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
|
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.
|
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-
|
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
|
@@ -453,9 +469,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
453
469
|
version: '2.7'
|
454
470
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
455
471
|
requirements:
|
456
|
-
- - "
|
472
|
+
- - ">="
|
457
473
|
- !ruby/object:Gem::Version
|
458
|
-
version:
|
474
|
+
version: '0'
|
459
475
|
requirements: []
|
460
476
|
rubygems_version: 3.1.6
|
461
477
|
signing_key:
|