Skip to content

Commit

Permalink
add attributes support in kitchen-inspec
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Hartmann <chris@lollyrock.com>
  • Loading branch information
chris-rock committed Nov 4, 2016
1 parent 0fe5f74 commit 6388bb4
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@ suites:
inspec_tests:
- path: ./test/integration/duplicates
- path: ./test/integration/duplicates
- name: attributes_inline
run_list:
- recipe[os_prepare]
verifier:
inspec_tests:
- path: ./test/integration/attributes
attributes:
user: bob
password: secret
- name: attributes_file
run_list:
- recipe[os_prepare]
verifier:
inspec_tests:
- test/integration/attributes
# - path: ./test/integration/attributes
attrs:
- test/integration/profile-attribute.yml
# before you are able to use the compliance plugin, you need to run
# insecure is only required if you use self-signed certificates
# $ inspec compliance login https://compliance.test --user admin --insecure --token ''
Expand Down
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ matrix:
bundler_args: "--without guard tools"
script: bundle exec rake $SUITE
env: SUITE="test:integration" OS='supermarket'
- rvm: 2.3.1
bundler_args: "--without guard tools"
script: bundle exec rake $SUITE
env: SUITE="test:integration" OS='attributes-inline attributes-file'
- rvm: ruby-head
allow_failures:
- rvm: ruby-head
1 change: 1 addition & 0 deletions kitchen-inspec.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
spec.required_ruby_version = ">= 2.1.0"
spec.add_dependency "inspec", ">=0.22.0", "<2.0.0"
spec.add_dependency "test-kitchen", "~> 1.6"
spec.add_dependency "hashie", "~> 3.4"
end
8 changes: 8 additions & 0 deletions lib/kitchen/verifier/inspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,15 @@ def finalize_config!(instance)
# (see Base#call)
def call(state)
logger.debug("Initialize InSpec")

# gather connection options
opts = runner_options(instance.transport, state)

# add attributes
opts[:attrs] = config[:attrs]
opts[:attributes] = Hashie.stringify_keys config[:attributes] unless config[:attributes].nil?

# initialize runner
runner = ::Inspec::Runner.new(opts)

# add each profile to runner
Expand Down
11 changes: 11 additions & 0 deletions test/integration/attributes/controls/example.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# encoding: utf-8
val_user = attribute("user", default: "alice", description: "An identification for the user")
val_password = attribute("password", description: "A value for the password")

describe val_user do
it { should eq "bob" }
end

describe val_password do
it { should eq "secret" }
end
8 changes: 8 additions & 0 deletions test/integration/attributes/inspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: attributes
title: InSpec Profile
maintainer: The Authors
copyright: The Authors
copyright_email: you@example.com
license: All Rights Reserved
summary: An InSpec Compliance Profile
version: 0.1.0
2 changes: 2 additions & 0 deletions test/integration/profile-attribute.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
user: bob
password: secret

0 comments on commit 6388bb4

Please sign in to comment.