Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add attributes support in kitchen-inspec #116

Merged
merged 2 commits into from
Nov 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,29 @@ suites:
compliance: base/ssh
```

### Use attributes with your inspec profiles

To run a profile with attributes defined inline, you can adapt your `.kitchen.yml`:

```yaml
verifier:
inspec_tests:
- path: test/integration/attributes
attributes:
user: bob
password: secret
```

You can also define your attributes in an external file. Adapt your `.kitchen.yml` to point to that file:

```yaml
verifier:
inspec_tests:
- path: test/integration/attributes
attrs:
- test/integration/profile-attribute.yml
```

## Development

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.
Expand Down
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