kitchen-inspec 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 93a2c2d193ca5d4c1eb991db653257d9b41781d3
4
+ data.tar.gz: b73c2b0e92c589261c0a0bf73383e1c2e4d4bd21
5
+ SHA512:
6
+ metadata.gz: 1a51f2dfa9b43219fa5e871aaf0ef18f64b497b5de3d07a7a52f2f831886bea5081e8ba0b3640b35eb21b55f3f5d1c0c0342bea9755785cc85a2ee106e270d06
7
+ data.tar.gz: 2441a9bfaf1a3b38568a568ac82ea277eec76ca827f33435d2851850d908da22eec4c3c57a8a5bf1476f9446739ac8d64c220e9177cfc12042b4d9ca61f0b4dd
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,17 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.2
5
+ - 2.1
6
+ - 2.0.0
7
+ - 1.9.3
8
+ - ruby-head
9
+
10
+ before_install: gem install bundler -v 1.10.6
11
+ bundler_args: --without guard
12
+
13
+ sudo: false
14
+
15
+ matrix:
16
+ allow_failures:
17
+ - rvm: ruby-head
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # -*- encoding: utf-8 -*-
2
+ source "https://rubygems.org"
3
+ gemspec
4
+
5
+ group :guard do
6
+ gem "guard-rspec", :require => nil
7
+ gem "guard-rubocop", :require => nil
8
+ end
9
+
10
+ group :test do
11
+ gem "codeclimate-test-reporter", :require => nil
12
+ end
data/Guardfile ADDED
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ ignore %r{^\.gem/}
3
+
4
+ def rspec_opts
5
+ { :cmd => "bundle exec rspec" }
6
+ end
7
+
8
+ def rubocop_opts
9
+ { :all_on_start => false, :keep_failed => false, :cli => "-r finstyle" }
10
+ end
11
+
12
+ group :red_green_refactor, :halt_on_fail => true do
13
+ guard :rspec, rspec_opts do
14
+ watch(%r{^spec/(.*)_spec\.rb})
15
+ watch(%r{^lib/(.*)([^/]+)\.rb}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
16
+ watch(%r{^spec/spec_helper\.rb}) { "spec" }
17
+ end
18
+
19
+ guard :rubocop, rubocop_opts do
20
+ watch(%r{.+\.rb$})
21
+ watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
22
+ end
23
+ end
data/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ Author:: Fletcher Nichol (<fnichol@chef.io>)
2
+
3
+ Copyright (C) 2015, Chef Software Inc.
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Kitchen::InSpec - A Test Kitchen Verifier for InSpec
2
+
3
+ This is the kitchen driver for [InSpec](https://github.com/chef/inspec). Please find an [example here](https://github.com/chef/inspec/tree/master/examples/test-kitchen)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'kitchen-inspec'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install kitchen-inspec
20
+
21
+ ## Usage
22
+
23
+ In your .kitchen.yml include
24
+ ```
25
+ verifier:
26
+ name: inspec
27
+ ```
28
+
29
+ ## Development
30
+
31
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
32
+
33
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/kitchen-inspec.
38
+
39
+ ## License
40
+
41
+ Apache 2.0 (see [LICENSE][license])
42
+
43
+ [license]: https://github.com/chef/kitchen-inspec/blob/master/LICENSE
data/Rakefile ADDED
@@ -0,0 +1,36 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require "bundler/gem_tasks"
4
+
5
+ require "rspec/core/rake_task"
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ desc "Run all test suites"
9
+ task :test => [:spec]
10
+
11
+ task :default => :spec
12
+
13
+ require "cane/rake_task"
14
+ desc "Run cane to check quality metrics"
15
+ Cane::RakeTask.new do |cane|
16
+ cane.canefile = "./.cane"
17
+ end
18
+
19
+ require "finstyle"
20
+ require "rubocop/rake_task"
21
+ RuboCop::RakeTask.new(:style) do |task|
22
+ task.options << "--display-cop-names"
23
+ end
24
+
25
+ desc "Display LOC stats"
26
+ task :stats do
27
+ puts "\n## Production Code Stats"
28
+ sh "countloc -r lib/kitchen"
29
+ puts "\n## Test Code Stats"
30
+ sh "countloc -r spec"
31
+ end
32
+
33
+ desc "Run all quality tasks"
34
+ task :quality => [:cane, :style, :stats]
35
+
36
+ task :default => [:test, :quality]
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "kitchen/inspec"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,38 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "kitchen/verifier/inspec_version"
5
+ require "English"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "kitchen-inspec"
9
+ spec.version = Kitchen::Verifier::INSPEC_VERSION
10
+ spec.license = "Apache 2.0"
11
+ spec.authors = ["Fletcher Nichol"]
12
+ spec.email = ["fnichol@chef.io"]
13
+
14
+ spec.summary = "A Test Kitchen Verifier for InSpec"
15
+ spec.description = spec.summary
16
+ spec.homepage = "http://github.com/chef/kitchen-inspec"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").
19
+ reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency "test-kitchen", "~> 1.4"
25
+ spec.add_dependency "inspec", "~> 0.9"
26
+
27
+ spec.add_development_dependency "countloc", "~> 0.4"
28
+ spec.add_development_dependency "bundler", "~> 1.10"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "rspec"
31
+ spec.add_development_dependency "simplecov", "~> 0.10"
32
+
33
+ # style and complexity libraries are tightly version pinned as newer releases
34
+ # may introduce new and undesireable style choices which would be immediately
35
+ # enforced in CI
36
+ spec.add_development_dependency "finstyle", "1.5.0"
37
+ spec.add_development_dependency "cane", "2.6.2"
38
+ end
@@ -0,0 +1,143 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # Author:: Fletcher Nichol (<fnichol@chef.io>)
4
+ # Author:: Christoph Hartmann (<chartmann@chef.io>)
5
+ #
6
+ # Copyright (C) 2015, Chef Software Inc.
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+
20
+ require "kitchen/verifier/inspec_version"
21
+ require "kitchen/verifier/base"
22
+
23
+ require "uri"
24
+
25
+ module Kitchen
26
+
27
+ module Verifier
28
+
29
+ # InSpec verifier for Kitchen.
30
+ #
31
+ # @author Fletcher Nichol <fnichol@chef.io>
32
+ class Inspec < Kitchen::Verifier::Base
33
+
34
+ kitchen_verifier_api_version 1
35
+
36
+ plugin_version Kitchen::Verifier::INSPEC_VERSION
37
+
38
+ # (see Base#call)
39
+ def call(state)
40
+ transport_data = instance.transport.diagnose.merge(state)
41
+
42
+ runner_options = case (name = instance.transport.name.downcase)
43
+ when "ssh"
44
+ runner_options_for_ssh(transport_data)
45
+ when "winrm"
46
+ runner_options_for_winrm(transport_data)
47
+ else
48
+ raise Kitchen::UserError, "Verifier #{name}",
49
+ " does not support the #{name} Transport"
50
+ end
51
+ tests = local_suite_files
52
+
53
+ runner = ::Inspec::Runner.new(runner_options)
54
+ runner.add_tests(tests)
55
+ debug("Running specs from: #{tests.inspect}")
56
+ runner.run
57
+ end
58
+
59
+ private
60
+
61
+ # Determines whether or not a local workstation file exists under a
62
+ # Chef-related directory.
63
+ #
64
+ # @return [truthy,falsey] whether or not a given file is some kind of
65
+ # Chef-related file
66
+ # @api private
67
+ def chef_data_dir?(base, file)
68
+ file =~ %r{^#{base}/(data|data_bags|environments|nodes|roles)/}
69
+ end
70
+
71
+ # (see Base#load_needed_dependencies!)
72
+ def load_needed_dependencies!
73
+ require "inspec"
74
+ end
75
+
76
+ # Returns an Array of test suite filenames for the related suite currently
77
+ # residing on the local workstation. Any special provisioner-specific
78
+ # directories (such as a Chef roles/ directory) are excluded.
79
+ #
80
+ # @return [Array<String>] array of suite files
81
+ # @api private
82
+ def local_suite_files
83
+ base = File.join(config[:test_base_path], config[:suite_name])
84
+ glob = File.join(base, "**/*_spec.rb")
85
+ Dir.glob(glob).reject do |f|
86
+ chef_data_dir?(base, f) || File.directory?(f)
87
+ end
88
+ end
89
+
90
+ # Returns a configuration Hash that can be passed to a `Inspec::Runner`.
91
+ #
92
+ # @return [Hash] a configuration hash of string-based keys
93
+ # @api private
94
+ def runner_options_for_ssh(config_data)
95
+ kitchen = instance.transport.send(:connection_options, config_data).dup
96
+
97
+ opts = {
98
+ "backend" => "ssh",
99
+ "logger" => logger,
100
+ # pass-in sudo config from kitchen verifier
101
+ "sudo" => config[:sudo],
102
+ "host" => kitchen[:hostname],
103
+ "port" => kitchen[:port],
104
+ "user" => kitchen[:username],
105
+ "keepalive" => kitchen[:keepalive],
106
+ "keepalive_interval" => kitchen[:keepalive_interval],
107
+ "connection_timeout" => kitchen[:timeout],
108
+ "connection_retries" => kitchen[:connection_retries],
109
+ "connection_retry_sleep" => kitchen[:connection_retry_sleep],
110
+ "max_wait_until_ready" => kitchen[:max_wait_until_ready],
111
+ "compression" => kitchen[:compression],
112
+ "compression_level" => kitchen[:compression_level]
113
+ }
114
+ opts["key_files"] = kitchen[:keys] unless kitchen[:keys].nil?
115
+ opts["password"] = kitchen[:password] unless kitchen[:password].nil?
116
+
117
+ opts
118
+ end
119
+
120
+ # Returns a configuration Hash that can be passed to a `Inspec::Runner`.
121
+ #
122
+ # @return [Hash] a configuration hash of string-based keys
123
+ # @api private
124
+ def runner_options_for_winrm(config_data)
125
+ kitchen = instance.transport.send(:connection_options, config_data).dup
126
+
127
+ opts = {
128
+ "backend" => "winrm",
129
+ "logger" => logger,
130
+ "host" => URI(kitchen[:endpoint]).hostname,
131
+ "port" => URI(kitchen[:endpoint]).port,
132
+ "user" => kitchen[:user],
133
+ "password" => kitchen[:pass],
134
+ "connection_retries" => kitchen[:connection_retries],
135
+ "connection_retry_sleep" => kitchen[:connection_retry_sleep],
136
+ "max_wait_until_ready" => kitchen[:max_wait_until_ready]
137
+ }
138
+
139
+ opts
140
+ end
141
+ end
142
+ end
143
+ end
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # Author:: Fletcher Nichol (<fnichol@chef.io>)
4
+ # Author:: Christoph Hartmann (<chartmann@chef.io>)
5
+ #
6
+ # Copyright (C) 2015, Chef Software Inc.
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+
20
+ module Kitchen
21
+
22
+ module Verifier
23
+
24
+ # Version string for InSpec Kitchen verifier
25
+ INSPEC_VERSION = "0.9.0"
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,184 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kitchen-inspec
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - Fletcher Nichol
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-11-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: test-kitchen
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: inspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.9'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: countloc
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.10'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.10'
111
+ - !ruby/object:Gem::Dependency
112
+ name: finstyle
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '='
116
+ - !ruby/object:Gem::Version
117
+ version: 1.5.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '='
123
+ - !ruby/object:Gem::Version
124
+ version: 1.5.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: cane
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '='
130
+ - !ruby/object:Gem::Version
131
+ version: 2.6.2
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '='
137
+ - !ruby/object:Gem::Version
138
+ version: 2.6.2
139
+ description: A Test Kitchen Verifier for InSpec
140
+ email:
141
+ - fnichol@chef.io
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - ".rspec"
148
+ - ".travis.yml"
149
+ - Gemfile
150
+ - Guardfile
151
+ - LICENSE
152
+ - README.md
153
+ - Rakefile
154
+ - bin/console
155
+ - bin/setup
156
+ - kitchen-inspec.gemspec
157
+ - lib/kitchen/verifier/inspec.rb
158
+ - lib/kitchen/verifier/inspec_version.rb
159
+ homepage: http://github.com/chef/kitchen-inspec
160
+ licenses:
161
+ - Apache 2.0
162
+ metadata: {}
163
+ post_install_message:
164
+ rdoc_options: []
165
+ require_paths:
166
+ - lib
167
+ required_ruby_version: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - ">="
170
+ - !ruby/object:Gem::Version
171
+ version: '0'
172
+ required_rubygems_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ requirements: []
178
+ rubyforge_project:
179
+ rubygems_version: 2.4.5.1
180
+ signing_key:
181
+ specification_version: 4
182
+ summary: A Test Kitchen Verifier for InSpec
183
+ test_files: []
184
+ has_rdoc: