lono-cfn 0.0.8 → 0.0.9

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: 7c8ca0b40036227cb0fdcbc68045dfe5e764d93d
4
- data.tar.gz: 99ecb021684fee61214f718a33e84918fd9b6322
3
+ metadata.gz: 2f3e597e125705a05cdcf0bf2d8d4cf77795b54a
4
+ data.tar.gz: fd7451b7d7bbf196c6768da44e9bcbd1d1852817
5
5
  SHA512:
6
- metadata.gz: 31e6cea19e34d327bd56d093d63979d225fb17b903be120a137de5fd1b8a01e6dda0ac743858cb94e17653da10a606976915c8f3290ea4f4234019e6c0eda7d4
7
- data.tar.gz: 16fae8cc421de79aa457e651e6ad38dae9e83321ddbe7dd2f102941d88afcf47f267aa1a9204db76c00cf6c792330c47e46459308afd8b6b682246ab82f86f1a
6
+ metadata.gz: 78662463e2e41e3bf24f1fe7bfca52e0971d8b455a74dd1e1359fcd14c7fe6217e61423e3940a72265fc7b3f16e5cb91edd4a6469be19a7c20ca8e6643661e88
7
+ data.tar.gz: fbbae100549f6acee6c32e06f40a9a25e0541621a7e6daa4370feed974c6d56282dceee0b38b212e524b65337c647f08d50de8007001c328efff2b443e8f63bd
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Lono Cfn
2
2
 
3
+ [![CircleCI](https://circleci.com/gh/tongueroo/lono-cfn.svg?style=svg)](https://circleci.com/gh/tongueroo/lono-cfn)
4
+
3
5
  Wrapper cfn tool to quickly create CloudFormation stacks from [lono templates](https://github.com/tongueroo/lono) and [lono-params](https://github.com/tongueroo/lono-params) files. Example:
4
6
 
5
7
  ```bash
@@ -95,8 +97,8 @@ The template that will be use is output/different-name3.json and the parameters
95
97
 
96
98
  ```bash
97
99
  $ git clone git@github.com:yourfork/lono-cfn.git
98
- $ git submodule init
99
- $ git submodule update
100
+ $ git submodule sync
101
+ $ git submodule update --init
100
102
  ```
101
103
 
102
104
  ## Related Projects
@@ -104,3 +106,4 @@ $ git submodule update
104
106
  * [lono](https://github.com/tongueroo/lono) - Lono is a CloudFormation Template generator. Lono generates CloudFormation templates based on ERB ruby templates.
105
107
  * [lono-params](https://github.com/tongueroo/lono-params) - Tool to generate a CloudFormation parameters json formatted file from a simplier env like file.
106
108
 
109
+ ith
data/circle.yml ADDED
@@ -0,0 +1,4 @@
1
+ checkout:
2
+ post:
3
+ - git submodule sync --recursive
4
+ - git submodule update --init --recursive
@@ -1,3 +1,3 @@
1
1
  module LonoCfn
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
data/lono_cfn.gemspec CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = "https://github.com/tongueroo/lono-cfn"
14
14
  spec.license = "MIT"
15
15
 
16
- spec.files = `git ls-files`.split($/)
16
+ spec.files = `git ls-files`.split($/) + Dir.glob("vendor/**/*")
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
@@ -0,0 +1,17 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ This project *tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
+
6
+ ## [0.0.5] do not generate param if the value is not set
7
+
8
+ - do not generate param if the value is not set
9
+
10
+ ## [0.0.4] Implement use_previous_value
11
+
12
+ - Implement use_previous_value: will create a hash with UsePreviousValue key.
13
+ - Allow trailing comment on the same line.
14
+
15
+ ## [0.0.1] Initial Release
16
+
17
+ - Initial release.
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in lono_params.gemspec
4
+ gemspec
5
+
6
+ gem "codeclimate-test-reporter", group: :test, require: nil
@@ -0,0 +1,115 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ lono-params (0.0.5)
5
+ colorize
6
+ hashie
7
+ plissken
8
+ thor
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ activemodel (4.2.8)
14
+ activesupport (= 4.2.8)
15
+ builder (~> 3.1)
16
+ activesupport (4.2.8)
17
+ i18n (~> 0.7)
18
+ minitest (~> 5.1)
19
+ thread_safe (~> 0.3, >= 0.3.4)
20
+ tzinfo (~> 1.1)
21
+ builder (3.2.3)
22
+ codeclimate-test-reporter (0.6.0)
23
+ simplecov (>= 0.7.1, < 1.0.0)
24
+ coderay (1.1.1)
25
+ colorize (0.8.1)
26
+ diff-lcs (1.2.5)
27
+ docile (1.1.5)
28
+ ffi (1.9.14)
29
+ formatador (0.2.5)
30
+ guard (2.14.0)
31
+ formatador (>= 0.2.4)
32
+ listen (>= 2.7, < 4.0)
33
+ lumberjack (~> 1.0)
34
+ nenv (~> 0.1)
35
+ notiffany (~> 0.0)
36
+ pry (>= 0.9.12)
37
+ shellany (~> 0.0)
38
+ thor (>= 0.18.1)
39
+ guard-bundler (2.1.0)
40
+ bundler (~> 1.0)
41
+ guard (~> 2.2)
42
+ guard-compat (~> 1.1)
43
+ guard-compat (1.2.1)
44
+ guard-rspec (4.7.3)
45
+ guard (~> 2.1)
46
+ guard-compat (~> 1.1)
47
+ rspec (>= 2.99.0, < 4.0)
48
+ hashie (3.5.5)
49
+ i18n (0.8.1)
50
+ json (2.0.2)
51
+ listen (3.1.5)
52
+ rb-fsevent (~> 0.9, >= 0.9.4)
53
+ rb-inotify (~> 0.9, >= 0.9.7)
54
+ ruby_dep (~> 1.2)
55
+ lumberjack (1.0.10)
56
+ method_source (0.8.2)
57
+ minitest (5.10.1)
58
+ nenv (0.3.0)
59
+ notiffany (0.1.1)
60
+ nenv (~> 0.1)
61
+ shellany (~> 0.0)
62
+ plissken (0.3.0)
63
+ symbolize (~> 4.2)
64
+ pry (0.10.4)
65
+ coderay (~> 1.1.0)
66
+ method_source (~> 0.8.1)
67
+ slop (~> 3.4)
68
+ rake (11.3.0)
69
+ rb-fsevent (0.9.7)
70
+ rb-inotify (0.9.7)
71
+ ffi (>= 0.5.0)
72
+ rspec (3.5.0)
73
+ rspec-core (~> 3.5.0)
74
+ rspec-expectations (~> 3.5.0)
75
+ rspec-mocks (~> 3.5.0)
76
+ rspec-core (3.5.3)
77
+ rspec-support (~> 3.5.0)
78
+ rspec-expectations (3.5.0)
79
+ diff-lcs (>= 1.2.0, < 2.0)
80
+ rspec-support (~> 3.5.0)
81
+ rspec-mocks (3.5.0)
82
+ diff-lcs (>= 1.2.0, < 2.0)
83
+ rspec-support (~> 3.5.0)
84
+ rspec-support (3.5.0)
85
+ ruby_dep (1.4.0)
86
+ shellany (0.0.1)
87
+ simplecov (0.12.0)
88
+ docile (~> 1.1.0)
89
+ json (>= 1.8, < 3)
90
+ simplecov-html (~> 0.10.0)
91
+ simplecov-html (0.10.0)
92
+ slop (3.6.0)
93
+ symbolize (4.5.2)
94
+ activemodel (>= 3.2, < 5)
95
+ activesupport (>= 3.2, < 5)
96
+ i18n
97
+ thor (0.19.1)
98
+ thread_safe (0.3.6)
99
+ tzinfo (1.2.3)
100
+ thread_safe (~> 0.1)
101
+
102
+ PLATFORMS
103
+ ruby
104
+
105
+ DEPENDENCIES
106
+ bundler (~> 1.3)
107
+ codeclimate-test-reporter
108
+ guard
109
+ guard-bundler
110
+ guard-rspec
111
+ lono-params!
112
+ rake
113
+
114
+ BUNDLED WITH
115
+ 1.14.6
@@ -0,0 +1,12 @@
1
+ guard 'rspec' do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { "spec/lono_params_spec.rb" }
4
+ watch(%r{^lib/lono_params/(.+)\.rb$}) { "spec/lono_params_spec.rb" }
5
+ watch('spec/spec_helper.rb') { "spec/lono_params_spec.rb" }
6
+ watch(%r{^lib/lono_params/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ end
8
+
9
+ guard 'bundler' do
10
+ watch('Gemfile')
11
+ watch(/^.+\.gemspec/)
12
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Tung Nguyen
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
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.
@@ -0,0 +1,72 @@
1
+ # Lono Params
2
+
3
+ Tool to generate a CloudFormation params json formatted file from a simple env file.
4
+
5
+ Given:
6
+
7
+ ```
8
+ Param1=1
9
+ # comments are fine
10
+ Param2=2 # comments can go after the line too
11
+ Param3=use_previous_value # treated specially
12
+ $
13
+ ```
14
+
15
+ This is produced:
16
+
17
+ ```json
18
+ [
19
+ {
20
+ "ParameterKey": "Param1",
21
+ "ParameterValue": "1"
22
+ },
23
+ {
24
+ "ParameterKey": "Param2",
25
+ "ParameterValue": "2"
26
+ },
27
+ {
28
+ "ParameterKey": "Param3",
29
+ "UsePreviousValue": true
30
+ }
31
+ ]
32
+ ```
33
+
34
+ ## Installation
35
+
36
+ Add this line to your application's Gemfile:
37
+
38
+ gem 'lono-params'
39
+
40
+ And then execute:
41
+
42
+ $ bundle
43
+
44
+ Or install it yourself as:
45
+
46
+ $ gem install lono-params
47
+
48
+ ## Usage
49
+
50
+ Create a directory under your project folder called `params`. Create a env file at `params/my-stack.txt`.
51
+
52
+ To generate the CloudFormation json file that can be used with the `aws cloudformation create-stack` command, run:
53
+
54
+ ```
55
+ $ lono-params generate my-stack
56
+ Params file generated for my-stack at ./output/params/my-stack.json
57
+ $
58
+ ```
59
+
60
+ ## More Help
61
+
62
+ ```
63
+ $ bin/lono-params help
64
+ ```
65
+
66
+ ## Contributing
67
+
68
+ 1. Fork it
69
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
70
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
71
+ 4. Push to the branch (`git push origin my-new-feature`)
72
+ 5. Create new Pull Request
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ task :default => :spec
5
+
6
+ RSpec::Core::RakeTask.new
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.expand_path('../../lib', __FILE__))
4
+ require 'lono-params'
5
+ require 'lono_params/cli'
6
+
7
+ LonoParams::CLI.start(ARGV)
@@ -0,0 +1,7 @@
1
+ $:.unshift(File.expand_path("../", __FILE__))
2
+ require "lono_params/version"
3
+
4
+ module LonoParams
5
+ autoload :CLI, 'lono_params/cli'
6
+ autoload :Generator, 'lono_params/generator'
7
+ end
@@ -0,0 +1,19 @@
1
+ module LonoParams
2
+ class CLI < Thor
3
+ class Help
4
+ class << self
5
+ def generate
6
+ <<-EOL
7
+ Example:
8
+
9
+ To generate a CloudFormation json file from params/my-stack.txt
10
+
11
+ $ lono-params generate my-stack
12
+
13
+ This will output a CloudFormation json file in output/params/my-stack.json
14
+ EOL
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,18 @@
1
+ require 'thor'
2
+ require 'lono_params/cli/help'
3
+
4
+ module LonoParams
5
+
6
+ class CLI < Thor
7
+ class_option :verbose, type: :boolean
8
+ class_option :noop, type: :boolean
9
+ class_option :project_root, desc: "project root to use", default: '.'
10
+
11
+ desc "generate NAME", "generate parameter json file for NAME"
12
+ long_desc Help.generate
13
+ option :path, desc: "Path of the source params txt file. Use this to override the params/NAME.txt convention"
14
+ def generate(name)
15
+ Generator.new(name, options).generate
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,85 @@
1
+ require "json"
2
+ require "fileutils"
3
+ require 'plissken' # Hash#to_snake_keys
4
+
5
+ module LonoParams
6
+ class Generator
7
+ def initialize(name, options)
8
+ @name = name
9
+ @options = options
10
+ @project_root = options[:project_root] || '.'
11
+ @source_path = options[:path] || "#{@project_root}/params/#{@name}.txt"
12
+ end
13
+
14
+ def generate
15
+ # useful option for lono-cfn
16
+ return if @options[:allow_no_file] && !File.exist?(@source_path)
17
+
18
+ if File.exist?(@source_path)
19
+ contents = IO.read(@source_path)
20
+ data = convert_to_cfn_format(contents)
21
+ json = JSON.pretty_generate(data)
22
+ write_output(json)
23
+ puts "Params file generated for #{@name} at #{output_path}"
24
+ else
25
+ puts "#{@source_path} could not be found? Are you sure it exist?"
26
+ exit 1
27
+ end
28
+ end
29
+
30
+ # useful for when calling CloudFormation via the aws-sdk gem
31
+ def params
32
+ # useful option for lono-cfn
33
+ return {} if @options[:allow_no_file] && !File.exist?(@source_path)
34
+
35
+ contents = IO.read(@source_path)
36
+ convert_to_cfn_format(contents, :underscore)
37
+ end
38
+
39
+ def parse_contents(contents)
40
+ lines = contents.split("\n")
41
+ # remove comment at the end of the line
42
+ lines.map! { |l| l.sub(/#.*/,'').strip }
43
+ # filter out commented lines
44
+ lines = lines.reject { |l| l =~ /(^|\s)#/i }
45
+ # filter out empty lines
46
+ lines = lines.reject { |l| l.strip.empty? }
47
+ lines
48
+ end
49
+
50
+ def convert_to_cfn_format(contents, casing=:camel)
51
+ lines = parse_contents(contents)
52
+ params = []
53
+ lines.each do |line|
54
+ key,value = line.strip.split("=").map {|x| x.strip}
55
+ param = if value == "use_previous_value"
56
+ {
57
+ ParameterKey: key,
58
+ UsePreviousValue: true
59
+ }
60
+ elsif value
61
+ {
62
+ ParameterKey: key,
63
+ ParameterValue: value
64
+ }
65
+ end
66
+ if param
67
+ param = param.to_snake_keys if casing == :underscore
68
+ params << param
69
+ end
70
+ end
71
+ params
72
+ end
73
+
74
+ def output_path
75
+ path = "#{@project_root}/output/params/#{@name}.json"
76
+ end
77
+
78
+ def write_output(json)
79
+ dir = File.dirname(output_path)
80
+ FileUtils.mkdir_p(dir) unless File.exist?(dir)
81
+ IO.write(output_path, json)
82
+ end
83
+
84
+ end
85
+ end
@@ -0,0 +1,3 @@
1
+ module LonoParams
2
+ VERSION = "0.0.5"
3
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'lono_params/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "lono-params"
8
+ spec.version = LonoParams::VERSION
9
+ spec.authors = ["Tung Nguyen"]
10
+ spec.email = ["tongueroo@gmail.com"]
11
+ spec.description = %q{Tool to generate a CloudFormation parameters json formatted file}
12
+ spec.summary = %q{Tool to generate a CloudFormation parameters json formatted file}
13
+ spec.homepage = "https://github.com/tongueroo/lono-params"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "thor"
22
+ spec.add_dependency "hashie"
23
+ spec.add_dependency "colorize"
24
+ spec.add_dependency "plissken"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.3"
27
+ spec.add_development_dependency "rake"
28
+ spec.add_development_dependency "guard"
29
+ spec.add_development_dependency "guard-bundler"
30
+ spec.add_development_dependency "guard-rspec"
31
+ end
@@ -0,0 +1,4 @@
1
+ # comments are fine
2
+ Param1=1
3
+ Param2=2 # comments can go after the line too
4
+ Param3=use_previous_value # treated specially
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ # to run specs with what's remembered from vcr
4
+ # $ rake
5
+ #
6
+ # to run specs with new fresh data from aws api calls
7
+ # $ rake clean:vcr ; time rake
8
+ describe LonoParams::CLI do
9
+ before(:all) do
10
+ @project_root = "spec/fixtures/my_project"
11
+ @args = "--project-root #{@project_root}"
12
+ end
13
+
14
+ describe "lono-params" do
15
+ context "generate" do
16
+ let(:output) { execute("bin/lono-params generate my-stack #{@args}") }
17
+ it "should generate output/params/my-stack.json params file" do
18
+ expect(output).to include("Params file generated for my-stack")
19
+ data = JSON.load(IO.read("#{@project_root}/output/params/my-stack.json"))
20
+ expect(data).to be_a(Array)
21
+ end
22
+
23
+ it "should treat use_previous_value as a special value" do
24
+ out = execute("bin/lono-params generate my-stack #{@args}")
25
+ expect(output).to include("Params file generated for my-stack")
26
+ data = JSON.load(IO.read("#{@project_root}/output/params/my-stack.json"))
27
+ param3 = data.last
28
+ expect(param3["UsePreviousValue"]).to be true
29
+ end
30
+
31
+ it "should remove comments" do
32
+ out = execute("bin/lono-params generate my-stack #{@args}")
33
+ expect(output).to include("Params file generated for my-stack")
34
+ data = JSON.load(IO.read("#{@project_root}/output/params/my-stack.json"))
35
+ expect(data.size).to eq 3
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,22 @@
1
+ ENV['TEST'] = '1'
2
+
3
+ require "codeclimate-test-reporter"
4
+ CodeClimate::TestReporter.start
5
+
6
+ require "pp"
7
+
8
+ root = File.expand_path('../../', __FILE__)
9
+ require "#{root}/lib/lono-params"
10
+
11
+ module Helpers
12
+ def execute(cmd)
13
+ puts "Running: #{cmd}" if ENV['DEBUG']
14
+ out = `#{cmd}`
15
+ puts out if ENV['DEBUG']
16
+ out
17
+ end
18
+ end
19
+
20
+ RSpec.configure do |c|
21
+ c.include Helpers
22
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lono-cfn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
@@ -198,6 +198,7 @@ files:
198
198
  - README.md
199
199
  - Rakefile
200
200
  - bin/lono-cfn
201
+ - circle.yml
201
202
  - lib/lono-cfn.rb
202
203
  - lib/lono_cfn/aws_services.rb
203
204
  - lib/lono_cfn/base.rb
@@ -214,6 +215,23 @@ files:
214
215
  - spec/fixtures/my_project/params/my-stack.txt
215
216
  - spec/lib/cli_spec.rb
216
217
  - spec/spec_helper.rb
218
+ - vendor/lono-params/CHANGELOG.md
219
+ - vendor/lono-params/Gemfile
220
+ - vendor/lono-params/Gemfile.lock
221
+ - vendor/lono-params/Guardfile
222
+ - vendor/lono-params/LICENSE.txt
223
+ - vendor/lono-params/README.md
224
+ - vendor/lono-params/Rakefile
225
+ - vendor/lono-params/bin/lono-params
226
+ - vendor/lono-params/lib/lono-params.rb
227
+ - vendor/lono-params/lib/lono_params/cli.rb
228
+ - vendor/lono-params/lib/lono_params/cli/help.rb
229
+ - vendor/lono-params/lib/lono_params/generator.rb
230
+ - vendor/lono-params/lib/lono_params/version.rb
231
+ - vendor/lono-params/lono_params.gemspec
232
+ - vendor/lono-params/spec/fixtures/my_project/params/my-stack.txt
233
+ - vendor/lono-params/spec/lib/cli_spec.rb
234
+ - vendor/lono-params/spec/spec_helper.rb
217
235
  homepage: https://github.com/tongueroo/lono-cfn
218
236
  licenses:
219
237
  - MIT