inspec-chef 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +23 -1
- data/inspec-chef.gemspec +2 -0
- data/lib/inspec-chef/input.rb +44 -10
- data/lib/inspec-chef/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f13512640633f549c0a190e61f94cc2044c9d551401ccb4371e8f1cd37cd102b
|
4
|
+
data.tar.gz: a47a60292470aad2385de9697c024f7457883fc64eedff78b455a79f7406b367
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e848365caa7f68c3a0f4509284a530f62095274540787201a458c39fdd077862765261b46d95acc9267874580c0f9045914172f5a53da284114e889831639936
|
7
|
+
data.tar.gz: 4ff246d1449d0266ebb3c8bb9774f7f77f0ff209f04cb9263defb492bc628d0ba964740c8fcd803a011507dca113a842a15e8797496b7319ff76cceaef8f91ce
|
data/README.md
CHANGED
@@ -21,7 +21,7 @@ the plugin from RubyGems and install/register it with InSpec.
|
|
21
21
|
|
22
22
|
You can verify successful installation via `inspec plugin list`
|
23
23
|
|
24
|
-
## Configuration
|
24
|
+
## Configuration for Chef Infra Server
|
25
25
|
|
26
26
|
Each plugin option may be set either as an environment variable, or as a plugin
|
27
27
|
option in your Chef InSpec configuration file at ~/.inspec/config.json. For
|
@@ -51,6 +51,28 @@ This plugin supports the following options:
|
|
51
51
|
| INSPEC_CHEF_CLIENT | chef_api_client | The name of the client of the Chef server to connect as |
|
52
52
|
| INSPEC_CHEF_KEY | chef_api_key | Path to the private certificate identifying the node |
|
53
53
|
|
54
|
+
## Configuration for TestKitchen
|
55
|
+
|
56
|
+
To allow dev/prod parity, this input plugin detects if it is called from within
|
57
|
+
TestKitchen. As these tests should not access the Chef Server (to provide the
|
58
|
+
needed test data instead of live data), it will then revert on using the
|
59
|
+
`data_bags_path` and `attributes` from kitchen's `provisioner` section:
|
60
|
+
|
61
|
+
```yaml
|
62
|
+
suites:
|
63
|
+
- name: default
|
64
|
+
verifier:
|
65
|
+
load_plugins: true
|
66
|
+
data_bags_path: "test/integration/data_bags"
|
67
|
+
attributes:
|
68
|
+
java:
|
69
|
+
install_flavor: "oracle"
|
70
|
+
```
|
71
|
+
|
72
|
+
Please note, that support for `load_plugins` is not available on versions 1.3.1
|
73
|
+
and below of the `kitchen-inspec` verifier plugin. Please check
|
74
|
+
[kitchen-inspec PR #247 on GitHub](https://github.com/inspec/kitchen-inspec/pull/247) for finding official versions supporting this feature.
|
75
|
+
|
54
76
|
## Usage
|
55
77
|
|
56
78
|
When this plugin is loaded, you can use databag items as inputs:
|
data/inspec-chef.gemspec
CHANGED
data/lib/inspec-chef/input.rb
CHANGED
@@ -16,15 +16,17 @@ module InspecPlugins::Chef
|
|
16
16
|
def initialize
|
17
17
|
@plugin_conf = Inspec::Config.cached.fetch_plugin_config("inspec-chef")
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
unless Inspec::Config.cached.final_options.logger.is_a?(Kitchen::Logger)
|
20
|
+
@chef_endpoint = fetch_plugin_setting("endpoint")
|
21
|
+
@chef_client = fetch_plugin_setting("client")
|
22
|
+
@chef_api_key = fetch_plugin_setting("key")
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
24
|
+
if chef_endpoint.nil? || chef_client.nil? || chef_api_key.nil?
|
25
|
+
raise "ERROR: Need configuration of chef endpoint, client name and api key."
|
26
|
+
end
|
26
27
|
|
27
|
-
|
28
|
+
connect_to_chef_server
|
29
|
+
end
|
28
30
|
end
|
29
31
|
|
30
32
|
# Fetch method used for Input plugins
|
@@ -44,6 +46,19 @@ module InspecPlugins::Chef
|
|
44
46
|
|
45
47
|
private
|
46
48
|
|
49
|
+
# Check if this is called from within TestKitchen
|
50
|
+
def inside_testkitchen?
|
51
|
+
!! defined?(::Kitchen::Logger)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Reach for Kitchen data and return its evaluated config
|
55
|
+
def kitchen_provisioner_config
|
56
|
+
require 'binding_of_caller'
|
57
|
+
kitchen = binding.callers.find { |b| b.frame_description == 'verify' }.receiver
|
58
|
+
|
59
|
+
kitchen.provisioner.send(:provided_config)
|
60
|
+
end
|
61
|
+
|
47
62
|
# Get plugin setting via environment, config file or default
|
48
63
|
def fetch_plugin_setting(setting_name, default = nil)
|
49
64
|
env_var_name = "INSPEC_CHEF_#{setting_name.upcase}"
|
@@ -62,14 +77,33 @@ module InspecPlugins::Chef
|
|
62
77
|
|
63
78
|
# Retrieve a Databag item from Chef Server
|
64
79
|
def get_databag_item(databag, item)
|
65
|
-
|
80
|
+
unless inside_testkitchen?
|
81
|
+
unless chef_api.data_bags.any? { |k| k.name == databag }
|
82
|
+
raise format('Databag "%s" not found on Chef Infra Server', databag)
|
83
|
+
end
|
84
|
+
|
85
|
+
chef_api.data_bag_item.fetch(item, bag: databag).data
|
86
|
+
else
|
87
|
+
config = kitchen_provisioner_config
|
88
|
+
filename = File.join(config[:data_bags_path], databag, item + '.json')
|
89
|
+
|
90
|
+
begin
|
91
|
+
contents = JSON.load(File.read(filename))
|
92
|
+
rescue
|
93
|
+
raise format('Error accessing databag file %s, check TestKitchen configuration', filename)
|
94
|
+
end
|
95
|
+
end
|
66
96
|
end
|
67
97
|
|
68
98
|
# Retrieve attributes of a node
|
69
99
|
def get_attributes(node)
|
70
|
-
|
100
|
+
unless inside_testkitchen?
|
101
|
+
data = get_search(:node, "name:#{node}")
|
71
102
|
|
72
|
-
|
103
|
+
merge_attributes(data)
|
104
|
+
else
|
105
|
+
kitchen_provisioner_config[:attributes]
|
106
|
+
end
|
73
107
|
end
|
74
108
|
|
75
109
|
# Low-level Chef search expression
|
data/lib/inspec-chef/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inspec-chef
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Heinen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-01-
|
11
|
+
date: 2020-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chef-api
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bump
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.8'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.8'
|
41
55
|
description: This plugin allows InSpec 'inputs' to be provided by Chef Server.
|
42
56
|
email:
|
43
57
|
- theinen@tecracer.de
|