lono 3.3.2 → 3.3.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
  SHA1:
3
- metadata.gz: 33b8dfbe5abe4a50a57843163b7d7d63c93fafe0
4
- data.tar.gz: d6683b919f81a8c5e0ec8c9e20ae600fadbe5d63
3
+ metadata.gz: f1b5263f718afe419807510969a58e1a7941c699
4
+ data.tar.gz: 973753a128ac8bdc500b55236384d3105d1e72f9
5
5
  SHA512:
6
- metadata.gz: a920f6e638ac50cd6ddefbb90b37211f6750d15d78cadab935ee8f5c959ce57c542022610a5dfd7a44dfd2a232d3f6da72c51d5ce73a51beb8ed3e2f0429903f
7
- data.tar.gz: 923d74376b825621cfd5c4a3c5a368f495cf99cca8be3a854065edbc5b54713a0b1eabd0cced82e80930dc38d51bfa66d44a30657f82b5bebf51d310bf7204fd
6
+ metadata.gz: d987aebfcba6f25a505eedf2d9be21ffa00d456492828fd8b5911253d33aaac705a0242caa95291abc5927e5771b959c62f59efb5b4133a0c29e092d9b49593b
7
+ data.tar.gz: f7c37945a9135c67573c3dfc513978df26f02ba34bf4c1834959a13e69993987c635463651999448d3d295a5be53bd45f4dbd23ff9d8188fdda54af286b0b8c5
@@ -3,6 +3,12 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
5
 
6
+ ## [3.3.4]
7
+ - require specific aws-sdk s3 and cloudformation dependencies to reduce size
8
+
9
+ ## [3.3.3]
10
+ - lono import also creates a params/base file
11
+
6
12
  ## [3.3.2]
7
13
  - remove -prod from the starter project
8
14
 
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012 Tung Nguyen
1
+ Copyright (c) 2017 Tung Nguyen
2
2
 
3
3
  MIT License
4
4
 
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
19
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
20
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
21
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -11,6 +11,7 @@ class Lono::Cfn < Lono::Command
11
11
  autoload :Delete, 'lono/cfn/delete'
12
12
  autoload :Preview, 'lono/cfn/preview'
13
13
  autoload :Diff, 'lono/cfn/diff'
14
+ autoload :Download, 'lono/cfn/download'
14
15
 
15
16
  class_option :verbose, type: :boolean
16
17
  class_option :noop, type: :boolean
@@ -64,4 +65,11 @@ class Lono::Cfn < Lono::Command
64
65
  def diff(name)
65
66
  Diff.new(name, options).run
66
67
  end
68
+
69
+ desc "download STACK", "download CloudFormation template from existing stack"
70
+ long_desc Help.download
71
+ option :name, desc: "Name you want to save the template as. Default: existing stack name."
72
+ def download(stack_name)
73
+ Download.new(stack_name, options).run
74
+ end
67
75
  end
@@ -1,4 +1,4 @@
1
- require "aws-sdk"
1
+ require "aws-sdk-cloudformation"
2
2
 
3
3
  module Lono::Cfn::AwsServices
4
4
  def cfn
@@ -0,0 +1,31 @@
1
+ require 'json'
2
+
3
+ class Lono::Cfn::Download < Lono::Cfn::Base
4
+ def run
5
+ puts "Download existing template to: #{download_path}"
6
+ return if @options[:noop]
7
+ download_template
8
+ end
9
+
10
+ def download_template
11
+ resp = cfn.get_template(
12
+ stack_name: @stack_name,
13
+ template_stage: "Original"
14
+ )
15
+ body = convert_to_yaml(resp.template_body)
16
+ IO.write(download_path, body)
17
+ end
18
+
19
+ def convert_to_yaml(body)
20
+ json?(body) ? YAML.dump(JSON.parse(body)) : body
21
+ end
22
+
23
+ def json?(body)
24
+ !!JSON.parse(body) rescue false
25
+ end
26
+
27
+ def download_path
28
+ name = @options[:name] || @stack_name
29
+ "/tmp/#{name}.yml"
30
+ end
31
+ end
@@ -87,6 +87,16 @@ Displays code diff of the generated CloudFormation template locally vs the exist
87
87
  Examples:
88
88
 
89
89
  $ lono cfn diff my-stack
90
+ EOL
91
+ end
92
+
93
+ def download
94
+ <<-EOL
95
+ Download CloudFormation template from existing template on AWS.
96
+
97
+ Examples:
98
+
99
+ $ lono cfn download my-stack
90
100
  EOL
91
101
  end
92
102
  end
@@ -15,10 +15,12 @@ class Lono::Importer
15
15
  unless options[:noop]
16
16
  download_template
17
17
  template_definition_path = add_template_definition
18
+ create_params
18
19
  puts "Imported raw CloudFormation template and lono-fied it!"
19
20
  puts "Template definition added to #{template_definition_path}."
21
+ puts "Params file created to #{params_path}."
20
22
  end
21
- puts "Template downloaded to #{dest_path}."
23
+ puts "Template downloaded to #{template_path}." # like having this message at the end
22
24
  end
23
25
 
24
26
  def download_template
@@ -30,9 +32,9 @@ class Lono::Importer
30
32
  JSON.pretty_generate(JSON.load(template))
31
33
  end
32
34
 
33
- folder = File.dirname(dest_path)
35
+ folder = File.dirname(template_path)
34
36
  FileUtils.mkdir_p(folder) unless File.exist?(folder)
35
- IO.write(dest_path, result)
37
+ IO.write(template_path, result)
36
38
  end
37
39
 
38
40
  # Add template definition to config/templates/base/stacks.rb.
@@ -48,7 +50,35 @@ class Lono::Importer
48
50
  path
49
51
  end
50
52
 
51
- def dest_path
53
+ # Creates starter params/base/[stack-name].txt file
54
+ def create_params
55
+ template = if @format == 'yml'
56
+ YAML.load_file(template_path)
57
+ else
58
+ JSON.load(IO.read(template_path))
59
+ end
60
+
61
+ result = []
62
+ required_parameters.each do |name, attributes|
63
+ result << "#{name}="
64
+ end
65
+ optional_parameters.each do |name, attributes|
66
+ key = "#{name}=".ljust(20, ' ')
67
+ result << "##{key} # optional"
68
+ end
69
+ content = result.join("\n") + "\n"
70
+
71
+ folder = File.dirname(params_path)
72
+ FileUtils.mkdir_p(folder) unless File.exist?(folder)
73
+ IO.write(params_path, content) unless File.exist?(params_path)
74
+ end
75
+
76
+ def params_path
77
+ "#{@project_root}/params/base/#{template_name}.txt"
78
+ end
79
+
80
+
81
+ def template_path
52
82
  "#{@project_root}/templates/#{template_name}.#{@format}"
53
83
  end
54
84
 
@@ -60,6 +90,24 @@ class Lono::Importer
60
90
  end
61
91
 
62
92
  private
93
+ def required_parameters
94
+ parameters.reject { |logical_id, p| p["Default"] }
95
+ end
96
+
97
+ def optional_parameters
98
+ parameters.select { |logical_id, p| p["Default"] }
99
+ end
100
+
101
+ def parameters
102
+ template_data["Parameters"] || []
103
+ end
104
+
105
+ def template_data
106
+ return @template_data if @template_data
107
+ template_path = "#{@project_root}/templates/#{template_name}.#{@format}"
108
+ @template_data = YAML.load(IO.read(template_path))
109
+ end
110
+
63
111
  def normalize_format(format)
64
112
  format == 'yaml' ? 'yml' : format
65
113
  end
@@ -4,13 +4,21 @@ class Lono::Inspector::Summary < Lono::Inspector::Base
4
4
  return if @options[:noop]
5
5
 
6
6
  puts "Parameters:"
7
- print_parameters("Required", required_parameters)
8
- print_parameters("Optional", optional_parameters)
7
+ print_parameters_summary
9
8
 
10
9
  puts "Resources:"
11
10
  print_resource_types
12
11
  end
13
12
 
13
+ def print_parameters_summary
14
+ if parameters.empty?
15
+ puts " There are no parameters"
16
+ else
17
+ print_parameters("Required", required_parameters)
18
+ print_parameters("Optional", optional_parameters)
19
+ end
20
+ end
21
+
14
22
  def print_parameters(label, parameters)
15
23
  puts "#{label}:"
16
24
  if parameters.empty?
@@ -27,11 +35,15 @@ class Lono::Inspector::Summary < Lono::Inspector::Base
27
35
  end
28
36
 
29
37
  def required_parameters
30
- data["Parameters"].reject { |logical_id, p| p["Default"] }
38
+ parameters.reject { |logical_id, p| p["Default"] }
31
39
  end
32
40
 
33
41
  def optional_parameters
34
- data["Parameters"].select { |logical_id, p| p["Default"] }
42
+ parameters.select { |logical_id, p| p["Default"] }
43
+ end
44
+
45
+ def parameters
46
+ data["Parameters"] || []
35
47
  end
36
48
 
37
49
  def resource_types
@@ -48,5 +60,6 @@ class Lono::Inspector::Summary < Lono::Inspector::Base
48
60
  type, count = a
49
61
  printf "%3s %s\n", count, type
50
62
  end
63
+ printf "%3s %s\n", resource_types.size, "Total"
51
64
  end
52
65
  end
@@ -1,4 +1,4 @@
1
- require "aws-sdk"
1
+ require "aws-sdk-s3"
2
2
 
3
3
  module Lono::Template::AwsServices
4
4
  def s3
@@ -1,3 +1,3 @@
1
1
  module Lono
2
- VERSION = "3.3.2"
2
+ VERSION = "3.3.4"
3
3
  end
@@ -26,7 +26,8 @@ Gem::Specification.new do |gem|
26
26
  gem.add_dependency "guard-lono"
27
27
  gem.add_dependency "colorize"
28
28
  gem.add_dependency "hashie"
29
- gem.add_dependency "aws-sdk", '~> 3'
29
+ gem.add_dependency "aws-sdk-cloudformation"
30
+ gem.add_dependency "aws-sdk-s3"
30
31
  gem.add_dependency "activesupport"
31
32
  gem.add_dependency "graph" # lono inspect depends
32
33
  # gem.add_dependency "plissken" # dependency for vendor/lono-params
@@ -30,6 +30,11 @@ describe Lono::Cfn do
30
30
  out = execute("bin/lono cfn diff my-stack #{@args}")
31
31
  expect(out).to include("diff")
32
32
  end
33
+
34
+ it "download stack" do
35
+ out = execute("bin/lono cfn download my-stack #{@args}")
36
+ expect(out).to include("Download")
37
+ end
33
38
  end
34
39
  end
35
40
 
@@ -5,6 +5,9 @@ describe Lono do
5
5
  before(:each) do
6
6
  @args = "--project-root spec/fixtures/my_project"
7
7
  end
8
+ after(:each) do
9
+ FileUtils.rm_rf("spec/fixtures/my_project/params/base")
10
+ end
8
11
 
9
12
  it "generate should build templates" do
10
13
  out = execute("./bin/lono generate #{@args}")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lono
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.2
4
+ version: 3.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-21 00:00:00.000000000 Z
11
+ date: 2017-12-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -123,19 +123,33 @@ dependencies:
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
- name: aws-sdk
126
+ name: aws-sdk-cloudformation
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - "~>"
129
+ - - ">="
130
130
  - !ruby/object:Gem::Version
131
- version: '3'
131
+ version: '0'
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - "~>"
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: aws-sdk-s3
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
137
144
  - !ruby/object:Gem::Version
138
- version: '3'
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
139
153
  - !ruby/object:Gem::Dependency
140
154
  name: activesupport
141
155
  requirement: !ruby/object:Gem::Requirement
@@ -247,7 +261,6 @@ files:
247
261
  - ".gitignore"
248
262
  - ".gitmodules"
249
263
  - ".rspec"
250
- - ".ruby-version"
251
264
  - ".travis.yml"
252
265
  - CHANGELOG.md
253
266
  - CONTRIBUTING.md
@@ -265,6 +278,7 @@ files:
265
278
  - lib/lono/cfn/create.rb
266
279
  - lib/lono/cfn/delete.rb
267
280
  - lib/lono/cfn/diff.rb
281
+ - lib/lono/cfn/download.rb
268
282
  - lib/lono/cfn/help.rb
269
283
  - lib/lono/cfn/preview.rb
270
284
  - lib/lono/cfn/update.rb
@@ -385,7 +399,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
385
399
  version: '0'
386
400
  requirements: []
387
401
  rubyforge_project:
388
- rubygems_version: 2.5.2
402
+ rubygems_version: 2.6.14
389
403
  signing_key:
390
404
  specification_version: 4
391
405
  summary: Lono is a CloudFormation Template ruby generator. Lono generates CloudFormation
@@ -1 +0,0 @@
1
- 2.3.3