mirror of
https://github.com/inspec/inspec
synced 2024-11-22 12:43:07 +00:00
update gordon with a bit of ruby and update README
This commit is contained in:
parent
1dce2037b3
commit
825702014c
4 changed files with 60 additions and 14 deletions
|
@ -1,5 +1,5 @@
|
|||
# encoding: utf-8
|
||||
# copyright: 2015, Chef Software, Inc.
|
||||
# copyright: 2016, Chef Software, Inc.
|
||||
# license: All rights reserved
|
||||
|
||||
include_controls 'profile' do
|
||||
|
|
|
@ -8,23 +8,41 @@ InSpec ships with built-in features to verify a profile structure.
|
|||
|
||||
```bash
|
||||
$ inspec check examples/profile
|
||||
I, [2015-11-21T12:44:50.851137 #20661] INFO -- : Checking profile in examples/profile
|
||||
I, [2015-11-21T12:44:50.851216 #20661] INFO -- : Metadata OK.
|
||||
D, [2015-11-21T12:44:50.851239 #20661] DEBUG -- : Found 2 rules.
|
||||
D, [2015-11-21T12:44:50.851251 #20661] DEBUG -- : Verify all rules in examples/profile/controls/example_spec.rb
|
||||
D, [2015-11-21T12:44:50.851263 #20661] DEBUG -- : Verify all rules in examples/profile/controls/gordon_spec.rb
|
||||
I, [2015-11-21T12:44:50.851317 #20661] INFO -- : Rule definitions OK.
|
||||
Summary
|
||||
-------
|
||||
Location: examples/profile
|
||||
Profile: profile
|
||||
Controls: 3
|
||||
Timestamp: 2016-03-24T16:20:21+00:00
|
||||
Valid: true
|
||||
|
||||
Errors
|
||||
------
|
||||
|
||||
Warnings
|
||||
--------
|
||||
```
|
||||
|
||||
## Execute a profile
|
||||
|
||||
To run a profile on a local machine use `inspec exec /path/to/profile`.
|
||||
To run all **supported** controls on a local machine use `inspec exec /path/to/profile`.
|
||||
|
||||
```bash
|
||||
$ inspec exec examples/profile
|
||||
..
|
||||
|
||||
Finished in 0.0025 seconds (files took 0.12449 seconds to load)
|
||||
2 examples, 0 failures
|
||||
|
||||
4 examples, 0 failures
|
||||
```
|
||||
|
||||
## Execute a specific control from a profile
|
||||
|
||||
To run one control from the profile use `inspec exec /path/to/profile --controls name`.
|
||||
|
||||
```bash
|
||||
$ inspec exec examples/profile --controls tmp-1.0
|
||||
.
|
||||
|
||||
Finished in 0.0025 seconds (files took 0.12449 seconds to load)
|
||||
1 examples, 0 failures
|
||||
```
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
# encoding: utf-8
|
||||
# copyright: 2015, Chef Software, Inc.
|
||||
# copyright: 2016, Chef Software, Inc.
|
||||
# license: All rights reserved
|
||||
|
||||
title 'Gordon Config Checks'
|
||||
|
||||
# To pass the test, create the following file
|
||||
# ```bash
|
||||
# cat <<EOF > /etc/gordon/config.yaml
|
||||
# mkdir -p /tmp/gordon
|
||||
# cat <<EOF > /tmp/gordon/config.yaml
|
||||
# version: '1.0'
|
||||
# EOF
|
||||
# ```
|
||||
|
@ -16,5 +17,6 @@ control 'gordon-1.0' do
|
|||
desc 'An optional description...'
|
||||
describe gordon_config do
|
||||
its('version') { should eq('1.0') }
|
||||
its('size') { should <= 20 }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,16 +1,42 @@
|
|||
require 'yaml'
|
||||
|
||||
# Custom resource based on the InSpec resource DSL
|
||||
class GordonConfig < Inspec.resource(1)
|
||||
name 'gordon_config'
|
||||
|
||||
desc "
|
||||
Gordon's resource description ...
|
||||
"
|
||||
|
||||
example "
|
||||
describe gordon_config do
|
||||
its('version') { should eq('1.0') }
|
||||
its('size') { should > 1 }
|
||||
end
|
||||
"
|
||||
|
||||
# Load the configuration file on initialization
|
||||
def initialize
|
||||
@path = '/etc/gordon/config.yaml'
|
||||
@path = '/tmp/gordon/config.yaml'
|
||||
@file = inspec.file(@path)
|
||||
return skip_resource "Can't find file \"#{@path}\"" if !@file.file?
|
||||
|
||||
@params = YAML.load(@file.content)
|
||||
# Protect from invalid YAML content
|
||||
begin
|
||||
@params = YAML.load(@file.content)
|
||||
rescue Exception
|
||||
return skip_resource "#{@file}: #{$!}"
|
||||
end
|
||||
add_some_extra_params
|
||||
end
|
||||
|
||||
# Extra Ruby helper method
|
||||
def add_some_extra_params
|
||||
@params['size']=@file.size
|
||||
@params['md5sum']=@file.md5sum
|
||||
end
|
||||
|
||||
# Expose all parameters
|
||||
def method_missing(name)
|
||||
@params[name.to_s]
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue