awshark 1.5.0 → 1.6.0

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: 1f20abce36658043c8b046859575b969365fd56528b3a786ca71e3009b078909
4
- data.tar.gz: 75631cf5ad34c594571a1f46297d3fa23c8da384c4789c43ea857a4ab09b972c
3
+ metadata.gz: bef9c837050b965232d2ecdb22ee410262cdd4bb204fbeafd5458bd515d5161a
4
+ data.tar.gz: 87fe084cc741d50679c804bfa7f4e946ff664cbb211ace537b0b17fb8604e325
5
5
  SHA512:
6
- metadata.gz: e75070ff5ad3295b994b9408edc5e448a205a413278b9dc6d2cae3b891840a976f6f5b0ccd9d8d4b9f6ba85fdf081ad1b3c83727712bea4228cb5248e659019b
7
- data.tar.gz: aa0feb28170116e34cab5a60ca8e60cfd6a6b76c9def7aaf78709aaa28a3475d2067bc39e76c9303481304ef11a757f69a54ebd4fdb9a0e1ce9cedf84c98d778
6
+ metadata.gz: e1ecb73e200abbacb8f9e0d40799e968ab33e801550c6ecf6c8b8400fedc6b0594792b6919653a78f25391be4a90804ffbb224593a8eaed67ed2fd2e0081010c
7
+ data.tar.gz: dc2f4213c6baa6bfcd14fe06a29e23457f9129f58e932f6d7562b3a5b763651d8ff36741152620f8bce2179331015e2e96fa380e4ed3ccfbfc95fb805a7d2094
data/.rubocop.yml CHANGED
@@ -4,11 +4,20 @@
4
4
  # See https://docs.rubocop.org/rubocop/configuration
5
5
 
6
6
  AllCops:
7
- TargetRubyVersion: 2.7
7
+ NewCops: enable
8
+ TargetRubyVersion: 3.1
8
9
  Exclude:
9
10
  - 'bin/*'
10
11
  - 'tmp/*'
11
12
 
13
+ Bundler/GemFilename:
14
+ EnforcedStyle: gems.rb
15
+
16
+ Gemspec/RequireMFA:
17
+ Enabled: false
18
+ Gemspec/RequiredRubyVersion:
19
+ Enabled: false
20
+
12
21
  Layout/BeginEndAlignment:
13
22
  Enabled: true
14
23
  EnforcedStyleAlignWith: begin
@@ -67,6 +76,7 @@ Lint/UselessMethodDefinition:
67
76
  Lint/UselessTimes:
68
77
  Enabled: true
69
78
 
79
+
70
80
  Metrics/AbcSize:
71
81
  Enabled: true
72
82
  Max: 25
@@ -85,6 +95,8 @@ Style/ExponentialNotation:
85
95
  Enabled: true
86
96
  Style/HashEachMethods:
87
97
  Enabled: true
98
+ Style/HashSyntax:
99
+ EnforcedShorthandSyntax: never
88
100
  Style/HashTransformKeys:
89
101
  Enabled: true
90
102
  Style/HashTransformValues:
@@ -117,6 +129,8 @@ Style/HashLikeCase:
117
129
  Enabled: true
118
130
  Style/KeywordParametersOrder:
119
131
  Enabled: true
132
+ Style/OpenStructUse:
133
+ Enabled: false
120
134
  Style/OptionalBooleanParameter:
121
135
  Enabled: true
122
136
  Style/RedundantAssignment:
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## Changelog
2
2
 
3
+ #### 1.6.0
4
+ - [new] `awshark cf [command] --format` option to export CF template not always as JSON ()
5
+
6
+ #### 1.5.1
7
+ - [new] `awshark cf [command] --bucket` option allows S3 path prefix
8
+
3
9
  #### 1.5.0
4
10
  - [new] add `awshark ssm list` to list AWS Parameter Store secrets
5
11
  - [new] add `awshark ssm deploy` to update AWS Parameter Store secrets
data/README.md CHANGED
@@ -47,12 +47,12 @@ awshark ecs list
47
47
 
48
48
  Display changes to AWS Cloud Formation stack.
49
49
  ```
50
- awshark cf diff TEMPLATE_PATH --stage=STAGE --bucket=S3_BUCKET.bundesimmo.de
50
+ awshark cf diff TEMPLATE_PATH --stage=STAGE --bucket=S3_BUCKET.bundesimmo.de --format=json|yaml
51
51
  ```
52
52
 
53
53
  Update or create AWS Cloud Formation stack.
54
54
  ```
55
- awshark cf deploy TEMPLATE_PATH --stage=STAGE --bucket=S3_BUCKET.bundesimmo.de
55
+ awshark cf deploy TEMPLATE_PATH --stage=STAGE --bucket=S3_BUCKET.bundesimmo.de --format=json|yaml
56
56
  ```
57
57
 
58
58
  Save AWS Cloud Formation stack as file `STACK_NAME-STAGE.json`.
data/awshark.gemspec CHANGED
@@ -42,8 +42,4 @@ Gem::Specification.new do |spec|
42
42
  spec.add_dependency 'mini_mime'
43
43
  spec.add_dependency 'recursive-open-struct'
44
44
  spec.add_dependency 'thor', '~> 1.0'
45
-
46
- spec.add_development_dependency 'bundler', '~> 2.0'
47
- spec.add_development_dependency 'rspec', '~> 3.9.0'
48
- spec.add_development_dependency 'rubocop', '0.93.1'
49
45
  end
data/gems.rb CHANGED
@@ -4,3 +4,7 @@ source 'https://rubygems.org'
4
4
 
5
5
  # Specify your gem's dependencies in awshark.gemspec
6
6
  gemspec
7
+
8
+ gem 'bundler', '~> 2.0'
9
+ gem 'rspec', '~> 3.12.0'
10
+ gem 'rubocop', '~> 1.56.4'
@@ -2,20 +2,23 @@
2
2
 
3
3
  module Awshark
4
4
  module CloudFormation
5
- module FileLoading
6
- def load_file(filepath, context = nil)
5
+ module Files
6
+ def parse_file(filepath)
7
7
  return nil if filepath.blank?
8
8
 
9
9
  content = File.read(filepath)
10
- content = ERB.new(content).result_with_hash(context) if context.present?
11
10
 
12
- case File.extname(filepath)
11
+ parse_string(filepath, content)
12
+ end
13
+
14
+ def parse_string(filename, content)
15
+ case File.extname(filename)
13
16
  when '.json'
14
17
  JSON.parse(content)
15
18
  when '.yml', '.yaml'
16
19
  YAML.safe_load(content, permitted_classes: [Date, Time], aliases: true)
17
20
  else
18
- raise ArgumentError, "Unsupported file extension for #{filepath}"
21
+ raise ArgumentError, "Unsupported file extension for parsing, #{filepath}"
19
22
  end
20
23
  end
21
24
  end
@@ -48,7 +48,7 @@ module Awshark
48
48
 
49
49
  def save_stack_template
50
50
  filename = "#{stack.name}.json"
51
- File.open(filename, 'w') { |f| f.write(template.body) }
51
+ File.write(filename, template.body)
52
52
  filename
53
53
  end
54
54
 
@@ -3,7 +3,7 @@
3
3
  module Awshark
4
4
  module CloudFormation
5
5
  class Parameters
6
- include FileLoading
6
+ include Files
7
7
 
8
8
  attr_reader :stage
9
9
 
@@ -34,7 +34,7 @@ module Awshark
34
34
  private
35
35
 
36
36
  def load_parameters(filepath)
37
- data = load_file(filepath) || {}
37
+ data = parse_file(filepath) || {}
38
38
 
39
39
  data[stage] || data
40
40
  end
@@ -77,9 +77,10 @@ module Awshark
77
77
  client.describe_stacks(stack_name: stack_name)
78
78
  rescue Aws::CloudFormation::Errors::ValidationError
79
79
  @stack = nil
80
- return
81
80
  end
82
81
 
82
+ return unless response.present?
83
+
83
84
  if response.stacks.length > 1
84
85
  raise ArgumentError, "Found too many stacks with name #{stack_name}. There should only be one."
85
86
  end
@@ -5,7 +5,7 @@ require 'aws-sdk-ssm'
5
5
  require 'diffy'
6
6
  require 'recursive-open-struct'
7
7
 
8
- require 'awshark/cloud_formation/file_loading'
8
+ require 'awshark/cloud_formation/files'
9
9
  require 'awshark/cloud_formation/inferrer'
10
10
  require 'awshark/cloud_formation/manager'
11
11
  require 'awshark/cloud_formation/parameters'
@@ -21,6 +21,7 @@ module Awshark
21
21
  class_option :bucket, type: :string, desc: 'S3 bucket for template'
22
22
  class_option :iam, type: :boolean, desc: 'Needs IAM capabilities'
23
23
  class_option :stage, type: :string, desc: 'Stage of the configuration'
24
+ class_option :format, type: :string, desc: 'Stage of the configuration', default: 'json'
24
25
 
25
26
  desc 'deploy', 'Updates or creates an AWS CloudFormation stack'
26
27
  long_desc <<-LONGDESC
@@ -3,34 +3,41 @@
3
3
  module Awshark
4
4
  module CloudFormation
5
5
  class Template
6
- include FileLoading
6
+ include Files
7
7
 
8
8
  attr_reader :path
9
- attr_reader :bucket, :name, :stage
9
+ attr_reader :bucket, :name, :stage, :format
10
10
 
11
11
  def initialize(path, options = {})
12
12
  @path = path
13
13
 
14
- @bucket = options[:bucket]
14
+ @bucket_and_path = options[:bucket]
15
+ @bucket = (options[:bucket] || '').split('/')[0]
15
16
  @name = options[:name]
16
17
  @stage = options[:stage]
18
+ @format = options[:format] || 'yaml'
17
19
  end
18
20
 
19
- # @returns [Hash]
20
- def as_json
21
- load_file(template_path, context)
22
- end
23
-
24
- # @returns [String]
21
+ # @returns String
25
22
  def body
26
- JSON.pretty_generate(as_json)
23
+ return nil if template_path.blank?
24
+
25
+ content = File.read(template_path)
26
+ content = ERB.new(content).result_with_hash(context)
27
+
28
+ if format == 'json'
29
+ json = parse_string(template_path, content)
30
+ return JSON.pretty_generate(json)
31
+ end
32
+
33
+ content
27
34
  end
28
35
 
29
36
  # @returns [Hash]
30
37
  def context
31
38
  @context ||=
32
39
  begin
33
- context = load_file(context_path) || {}
40
+ context = parse_file(context_path) || {}
34
41
  context = context[stage] if context.key?(stage)
35
42
 
36
43
  {
@@ -77,8 +84,11 @@ module Awshark
77
84
  end
78
85
 
79
86
  def s3_key
80
- # https://apidock.com/ruby/Time/strftime
81
- @s3_key ||= "awshark/#{name}/#{Time.now.strftime('%Y-%m-%d')}.json"
87
+ return @s3_key if defined?(@s3_key)
88
+
89
+ _, *tail = @bucket_and_path.split('/')
90
+ prefix = [*tail, 'awshark', name].join('/')
91
+ @s3_key = "#{prefix}/#{Time.now.strftime('%Y-%m-%d')}.json"
82
92
  end
83
93
 
84
94
  def upload
@@ -3,12 +3,12 @@
3
3
  module Awshark
4
4
  class ProfileResolver
5
5
  def initialize(options)
6
- @profile = options[:profile] || ENV['AWS_PROFILE']
6
+ @profile = options[:profile] || ENV.fetch('AWS_PROFILE')
7
7
  @shared_config = ::Aws::SharedConfig.new(
8
8
  profile_name: @profile,
9
9
  config_enabled: true
10
10
  )
11
- @region = options[:region] || ENV['REGION']
11
+ @region = options[:region] || ENV.fetch('REGION', nil)
12
12
  end
13
13
 
14
14
  def credentials
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Awshark
4
- VERSION = '1.5.0'
4
+ VERSION = '1.6.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awshark
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joergen Dahlke
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-01-10 00:00:00.000000000 Z
11
+ date: 2023-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -192,48 +192,6 @@ dependencies:
192
192
  - - "~>"
193
193
  - !ruby/object:Gem::Version
194
194
  version: '1.0'
195
- - !ruby/object:Gem::Dependency
196
- name: bundler
197
- requirement: !ruby/object:Gem::Requirement
198
- requirements:
199
- - - "~>"
200
- - !ruby/object:Gem::Version
201
- version: '2.0'
202
- type: :development
203
- prerelease: false
204
- version_requirements: !ruby/object:Gem::Requirement
205
- requirements:
206
- - - "~>"
207
- - !ruby/object:Gem::Version
208
- version: '2.0'
209
- - !ruby/object:Gem::Dependency
210
- name: rspec
211
- requirement: !ruby/object:Gem::Requirement
212
- requirements:
213
- - - "~>"
214
- - !ruby/object:Gem::Version
215
- version: 3.9.0
216
- type: :development
217
- prerelease: false
218
- version_requirements: !ruby/object:Gem::Requirement
219
- requirements:
220
- - - "~>"
221
- - !ruby/object:Gem::Version
222
- version: 3.9.0
223
- - !ruby/object:Gem::Dependency
224
- name: rubocop
225
- requirement: !ruby/object:Gem::Requirement
226
- requirements:
227
- - - '='
228
- - !ruby/object:Gem::Version
229
- version: 0.93.1
230
- type: :development
231
- prerelease: false
232
- version_requirements: !ruby/object:Gem::Requirement
233
- requirements:
234
- - - '='
235
- - !ruby/object:Gem::Version
236
- version: 0.93.1
237
195
  description: Custom CLI for for AWS to simplify common tasks with EC2, S3 and Cloud
238
196
  Formation
239
197
  email:
@@ -255,7 +213,7 @@ files:
255
213
  - lib/awshark/class_options.rb
256
214
  - lib/awshark/cli.rb
257
215
  - lib/awshark/cloud_formation/configuration.rb
258
- - lib/awshark/cloud_formation/file_loading.rb
216
+ - lib/awshark/cloud_formation/files.rb
259
217
  - lib/awshark/cloud_formation/inferrer.rb
260
218
  - lib/awshark/cloud_formation/manager.rb
261
219
  - lib/awshark/cloud_formation/parameters.rb