inspec-chef 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e3689a6a012e43692366a808c0b50e67e7ef4cb35b303593f84ca0d0cd485fd9
4
- data.tar.gz: 9c21ced8d8c706daf806553c6317b8ff375b3f5d40b0a6ac06573a33c6cb5df4
3
+ metadata.gz: 5d92257a6fe51e2e753b38cec027da0e1d81578cf9cd96bc941e17ffbf2957ab
4
+ data.tar.gz: 93d8dea2ff6a1f8d8040543e4bccb4316001c017459cb392f12edaf49ec33633
5
5
  SHA512:
6
- metadata.gz: b2f09ae34094154758c65afa303f4311ab2a4ea85f70b0a9e96a4cf58791c03cf74b33efce3f9477c26464de24027ce36c80fed92b3902949a7ecbef0219db62
7
- data.tar.gz: a71465e35f0ed3a99b5ce1e61f8252669b8a4544d1bddac24c447bdfbf55d66a58598bc4644b412975c50fdf8c8ca5a5ca269255d46a7552030b094459385dae
6
+ metadata.gz: c43fc11316341123dfff07d7eb1d8afe4515d53ab4f0bb7c8d36cb5e7f94683dad316be341d79fbd3f484f23dabdd554e5ae17bacef97e6b02fa17fc8422c09c
7
+ data.tar.gz: de6d24d7ed8d75e6f297d9ca30605db58009308b1e09397f9f8c46413f173037501cec8afb2533665fb7b98b7e2d881e056d4ce77b748d824b36f7275142fab7
data/inspec-chef.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.email = ["theinen@tecracer.de"]
22
22
  spec.summary = "InSpec input plugin to access Chef Infra Server databags and attributes."
23
23
  spec.description = "This plugin allows InSpec 'inputs' to be provided by Chef Server."
24
- spec.homepage = "https://github.com/tecracer-theinen/inspec-chef"
24
+ spec.homepage = "https://github.com/sgre-chef/inspec-chef"
25
25
  spec.license = "Apache-2.0"
26
26
 
27
27
  # Though complicated-looking, this is pretty standard for a gemspec.
@@ -16,26 +16,15 @@ module InspecPlugins::Chef
16
16
  # Set up new class
17
17
  def initialize
18
18
  @plugin_conf = Inspec::Config.cached.fetch_plugin_config("inspec-chef")
19
-
20
- unless defined?(Kitchen)
21
- @chef_endpoint = fetch_plugin_setting("endpoint")
22
- @chef_client = fetch_plugin_setting("client")
23
- @chef_api_key = fetch_plugin_setting("key")
24
-
25
- if chef_endpoint.nil? || chef_client.nil? || chef_api_key.nil?
26
- raise "ERROR: Need configuration of chef endpoint, client name and api key."
27
- end
28
-
29
- connect_to_chef_server
30
- end
31
19
  end
32
20
 
33
21
  # Fetch method used for Input plugins
34
22
  def fetch(_profile_name, input_uri)
35
23
  return nil unless valid_plugin_input? input_uri
36
24
 
37
- input = parse_input(input_uri)
25
+ connect_to_chef_server
38
26
 
27
+ input = parse_input(input_uri)
39
28
  if input[:type] == :databag
40
29
  data = get_databag_item(input[:object], input[:item])
41
30
  elsif input[:type] == :node
@@ -92,13 +81,33 @@ module InspecPlugins::Chef
92
81
 
93
82
  # Establish a Chef Server connection
94
83
  def connect_to_chef_server
95
- @chef_api ||= ChefAPI::Connection.new(
96
- endpoint: chef_endpoint,
97
- client: chef_client,
98
- key: chef_api_key
99
- )
84
+ # From within TestKitchen we need no Chef Server connection
85
+ if defined?(Kitchen)
86
+ Inspec::Log.info "Running from TestKitchen, using provisioner settings instead of Chef Server"
87
+
88
+ # Only connect once
89
+ elsif !connected?
90
+ @chef_endpoint = fetch_plugin_setting("endpoint")
91
+ @chef_client = fetch_plugin_setting("client")
92
+ @chef_api_key = fetch_plugin_setting("key")
93
+
94
+ if chef_endpoint.nil? || chef_client.nil? || chef_api_key.nil?
95
+ raise "ERROR: Plugin inspec-chef needs configuration of chef endpoint, client name and api key."
96
+ end
97
+
98
+ @chef_api ||= ChefAPI::Connection.new(
99
+ endpoint: chef_endpoint,
100
+ client: chef_client,
101
+ key: chef_api_key
102
+ )
103
+
104
+ Inspec::Log.debug format("Connected to %s as client %s", chef_endpoint, chef_client)
105
+ end
106
+ end
100
107
 
101
- Inspec::Log.debug format("Connected to %s as client %s", chef_endpoint, chef_client)
108
+ # Return if connection is established
109
+ def connected?
110
+ ! @chef_api.nil?
102
111
  end
103
112
 
104
113
  # Retrieve a Databag item from Chef Server
@@ -5,6 +5,6 @@
5
5
  # to learn the current version.
6
6
  module InspecPlugins
7
7
  module Chef
8
- VERSION = "0.3.0".freeze
8
+ VERSION = "0.3.1".freeze
9
9
  end
10
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inspec-chef
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Heinen
@@ -66,7 +66,7 @@ files:
66
66
  - lib/inspec-chef/input.rb
67
67
  - lib/inspec-chef/plugin.rb
68
68
  - lib/inspec-chef/version.rb
69
- homepage: https://github.com/tecracer-theinen/inspec-chef
69
+ homepage: https://github.com/sgre-chef/inspec-chef
70
70
  licenses:
71
71
  - Apache-2.0
72
72
  metadata: {}