Skip to content

Commit

Permalink
add the ability to install gem as package when specified
Browse files Browse the repository at this point in the history
Signed-off-by: Victoria Jeffrey <vjeffrey@chef.io>
  • Loading branch information
Victoria Jeffrey committed Nov 17, 2016
1 parent f1b8692 commit bbde422
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 3 deletions.
4 changes: 4 additions & 0 deletions attributes/default.rb
Expand Up @@ -22,6 +22,10 @@
# root of location must host the *specs.4.8.gz source index
default['audit']['inspec_gem_source'] = nil

# Used in cases where the desired install of inspec is via package instead of gem
# Default to false, set to true if needed. Setting to true will skip the inspec recipe and use inspec_package recipe
default['audit']['inspec_package'] = false

# collector possible values: chef-server, chef-compliance, chef-visibility, chef-server-visibility, json-file
# chef-visibility requires inspec version 0.27.1 or above
default['audit']['collector'] = 'chef-server'
Expand Down
1 change: 1 addition & 0 deletions metadata.rb
Expand Up @@ -13,3 +13,4 @@
chef_version '>= 12.5.1' if respond_to?(:chef_version)

depends 'compat_resource'
depends 'chef-ingredient'
9 changes: 6 additions & 3 deletions recipes/default.rb
Expand Up @@ -17,6 +17,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

include_recipe 'audit::inspec'

load_audit_handler
if node['audit']['inspec_package']
include_recipe 'audit::inspec_package'
else
include_recipe 'audit::inspec'
load_audit_handler
end
28 changes: 28 additions & 0 deletions recipes/inspec_package.rb
@@ -0,0 +1,28 @@
# encoding: utf-8
#
# Cookbook Name:: audit
# Recipe:: inspec_package
#
# Copyright 2016 Chef Software, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

chef_ingredient 'inspec' do
version node['audit']['inspec_version'] if node['audit']['inspec_version'] != 'latest'
accept_license true
action :upgrade
end

load_inspec_libs

load_audit_handler
33 changes: 33 additions & 0 deletions spec/unit/recipes/default_spec.rb
Expand Up @@ -69,6 +69,39 @@
end
end

context 'When a package install is specified' do
let(:chef_run) do
ChefSpec::ServerRunner.new do |node|
node.override['audit']['inspec_package'] = true
end.converge(described_recipe)
end

it 'does not install the inspec gem' do
expect(chef_run).to_not install_chef_gem('inspec')
end

it 'upgrades the inspec resource' do
expect(chef_run).to upgrade_chef_ingredient('inspec')
end

it 'converges successfully' do
expect { chef_run }.to_not raise_error
end
end

context 'When a package install and a version is specified' do
let(:chef_run) do
ChefSpec::ServerRunner.new do |node|
node.override['audit']['inspec_version'] = '0.0.0'
node.override['audit']['inspec_package'] = true
end.converge(described_recipe)
end

it 'installs the correct package version' do
expect(chef_run).to upgrade_chef_ingredient('inspec').with(version: '0.0.0')
end
end

context 'When server and refresh_token are specified' do
let(:chef_run) do
ChefSpec::ServerRunner.new do |node|
Expand Down

0 comments on commit bbde422

Please sign in to comment.