guard-cloudformation 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
@@ -0,0 +1 @@
1
+ 1.9.3@guard-cloudformation
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ bundler_args: --without development
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in guard-cloudformation.gemspec
4
+ gemspec :development_group => :test
5
+
6
+ group :test do
7
+ gem "rake"
8
+ gem "rspec"
9
+ gem "travis-lint"
10
+ end
11
+
12
+ group :development do
13
+ gem "growl"
14
+ gem "guard-bundler"
15
+ gem "guard-rspec"
16
+ gem "rb-fsevent"
17
+ end
@@ -0,0 +1,11 @@
1
+ guard "bundler" do
2
+ watch("Gemfile")
3
+ watch(/^.+\.gemspec/)
4
+ end
5
+
6
+ guard "rspec", :version => 2, :cli=> "--format nested" do
7
+ watch(%r{^spec/.+_spec\.rb$})
8
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
9
+ watch("spec/spec_helper.rb") { "spec" }
10
+ watch(%r{^spec/support/(.+)\.rb$}) { |m| "spec" }
11
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 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,32 @@
1
+ # Guard::Cloudformation
2
+
3
+ Guard::Cloudformation automatically runs validates cloud formation templates via cfn-validate-template.
4
+
5
+ ## Installation
6
+
7
+ Please be sure to AWS cfn cli tools install:
8
+
9
+ $ brew install aws-cfn-tools
10
+
11
+ Please be sure to have [Guard](https://github.com/guard/guard) installed before continuing.
12
+
13
+ Install the gem:
14
+
15
+ $ gem install guard-cloudformation
16
+
17
+ Add the guard-cloudformation definition to your Guardfile by running this command:
18
+
19
+ $ guard init cloudformation
20
+
21
+ ## Options
22
+
23
+ ```ruby
24
+ :all_on_start => false # Whether to run validate all Cloudformation templates on start up
25
+ # default: true
26
+
27
+ :templates_path => "." # The path(s) to your Cloudformation templates
28
+ # default: ["templates"]
29
+
30
+ :notification => false # Whether to display notifications after the validation is done running
31
+ # default: true
32
+ ```
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require "rspec/core/rake_task"
4
+
5
+ task :default => :spec
6
+
7
+ RSpec::Core::RakeTask.new
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/guard/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Tung Nguyen"]
6
+ gem.email = ["tongueroo@gmail.com"]
7
+ gem.description = %q{Guard::Cloudformation automatically validates cloud formation templates.}
8
+ gem.summary = %q{Guard::Cloudformation automatically validates cloud formation templates.}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "guard-cloudformation"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Guard::CLOUDFORMATION_VERSION
17
+
18
+ gem.add_dependency "colorize"
19
+ gem.add_dependency "guard"
20
+ end
@@ -0,0 +1,74 @@
1
+ require "guard"
2
+ require "guard/guard"
3
+ require "colorize"
4
+
5
+ module Guard
6
+ class Cloudformation < Guard
7
+
8
+ # Initialize a Guard.
9
+ # @param [Array<Guard::Watcher>] watchers the Guard file watchers
10
+ # @param [Hash] options the custom Guard options
11
+ def initialize(watchers = [], options = {})
12
+ super
13
+ @options = {
14
+ :all_on_start => true,
15
+ :templates_path => "templates",
16
+ :notification => true,
17
+ }.merge(@options)
18
+ end
19
+
20
+ # Call once when Guard starts. Please override initialize method to init stuff.
21
+ # @raise [:task_has_failed] when start has failed
22
+ def start
23
+ run_all if @options[:all_on_start]
24
+ end
25
+
26
+ # Called when just `enter` is pressed
27
+ # This method should be principally used for long action like running all specs/tests/...
28
+ # @raise [:task_has_failed] when run_all has failed
29
+ def run_all
30
+ paths = all_paths
31
+ run!(paths)
32
+ end
33
+
34
+ # Called on file(s) modifications that the Guard watches.
35
+ # @param [Array<String>] paths the changes files or paths
36
+ # @raise [:task_has_failed] when run_on_change has failed
37
+ def run_on_change(paths)
38
+ run!(paths)
39
+ end
40
+
41
+ private
42
+
43
+ def all_paths
44
+ Dir.glob("#{@options[:templates_path]}/*")
45
+ end
46
+
47
+ def run!(paths)
48
+ if validate(paths)
49
+ Notifier.notify "Cloud formation templates are valid", :image => :success if @options[:notification]
50
+ else
51
+ Notifier.notify "Cloud formation templates are invalid", :image => :failed if @options[:notification]
52
+ throw :task_has_failed
53
+ end
54
+ end
55
+
56
+ def validate(paths)
57
+ UI.info "Validating: #{paths.join(' ')}".green
58
+ all_success = true
59
+ paths.each do |path|
60
+ puts "Validating #{path}...".green
61
+ success = command(path)
62
+ if !success
63
+ puts "FAILED: #{path}".red
64
+ all_success = false
65
+ end
66
+ end
67
+ all_success
68
+ end
69
+
70
+ def command(path)
71
+ system "cfn-validate-template --template-file #{path}"
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,3 @@
1
+ guard "cloudformation", :templates_path => "templates" do
2
+ watch(%r{^templates/.+\.json$})
3
+ end
@@ -0,0 +1,3 @@
1
+ module Guard
2
+ CLOUDFORMATION_VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,28 @@
1
+ require "spec_helper"
2
+ require "guard/cloudformation"
3
+
4
+ module Guard
5
+ describe Cloudformation do
6
+ before { Notifier.stub(:notify) }
7
+
8
+ it { should be_a_kind_of ::Guard::Guard }
9
+
10
+ describe "#run_all" do
11
+ subject { guard.run_all }
12
+ let(:guard) { described_class.new [], :templates_path => "templates", :notification => notification }
13
+ let(:notification) { false }
14
+ let(:command) { mock "command" }
15
+ before do
16
+ guard.stub(:command).and_return(command)
17
+ guard.stub(:all_paths).and_return(["/path/1", "/path/2"])
18
+ end
19
+
20
+ it "runs validate for templates" do
21
+ guard.should_receive(:command).exactly(2).times
22
+ subject
23
+ end
24
+ end
25
+
26
+ end
27
+ end
28
+
@@ -0,0 +1,14 @@
1
+ require "bundler/setup"
2
+ require "rspec/autorun"
3
+
4
+ ENV["GUARD_ENV"] = "test"
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |file| require file }
9
+
10
+ RSpec.configure do |config|
11
+ config.treat_symbols_as_metadata_keys_with_true_values = true
12
+ config.run_all_when_everything_filtered = true
13
+ config.filter_run :focus
14
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guard-cloudformation
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tung Nguyen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: colorize
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: guard
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Guard::Cloudformation automatically validates cloud formation templates.
47
+ email:
48
+ - tongueroo@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - .rspec
55
+ - .ruby-version
56
+ - .travis.yml
57
+ - Gemfile
58
+ - Guardfile
59
+ - LICENSE
60
+ - README.md
61
+ - Rakefile
62
+ - guard-cloudformation.gemspec
63
+ - lib/guard/cloudformation.rb
64
+ - lib/guard/cloudformation/templates/Guardfile
65
+ - lib/guard/version.rb
66
+ - spec/cloudformation_spec.rb
67
+ - spec/spec_helper.rb
68
+ homepage: ''
69
+ licenses: []
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 1.8.24
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: Guard::Cloudformation automatically validates cloud formation templates.
92
+ test_files:
93
+ - spec/cloudformation_spec.rb
94
+ - spec/spec_helper.rb