diff --git a/README.md b/README.md index 2e697c8c..e9757db0 100644 --- a/README.md +++ b/README.md @@ -382,6 +382,19 @@ You can enable the interval and set the interval time, along with your desired p ``` +## Alternate Source Location for `inspec` Gem + +If you are not able or do not wish to pull the `inspec` gem from rubygems.org, +you may specify an alternate source using: + +``` +# URI to alternate gem source (e.g. http://gems.server.com or filesytem location) +# root of location must host the *specs.4.8.gz source index +default['audit']['inspec_gem_source'] = 'http://internal.gem.server.com/gems' +``` + +Please note that all dependencies to the `inspec` gem must also be hosted in this location. + ## Troubleshooting Please refer to TROUBLESHOOTING.md. diff --git a/attributes/default.rb b/attributes/default.rb index c31b6335..2ec84e9a 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -18,6 +18,10 @@ # inspec gem version to install(e.g. '1.1.0') default['audit']['inspec_version'] = '1.2.0' +# URI to alternate gem source (e.g. http://gems.server.com) +# root of location must host the *specs.4.8.gz source index +default['audit']['inspec_gem_source'] = nil + # collector possible values: chef-server, chef-compliance, chef-visibility, json-file # chef-visibility requires inspec version 0.27.1 or above default['audit']['collector'] = 'chef-server' diff --git a/recipes/default.rb b/recipes/default.rb index 6884dea9..54a01118 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -1,6 +1,8 @@ chef_gem 'inspec' do version node['audit']['inspec_version'] if node['audit']['inspec_version'] != 'latest' compile_time true + clear_sources true if node['audit']['inspec_gem_source'] + source node['audit']['inspec_gem_source'] if node['audit']['inspec_gem_source'] action :install end diff --git a/recipes/upload.rb b/recipes/upload.rb index 6537e94b..a898952e 100644 --- a/recipes/upload.rb +++ b/recipes/upload.rb @@ -21,6 +21,8 @@ chef_gem 'inspec' do version node['audit']['inspec_version'] if node['audit']['inspec_version'] != 'latest' compile_time true + clear_sources true if node['audit']['inspec_gem_source'] + source node['audit']['inspec_gem_source'] if node['audit']['inspec_gem_source'] action :install end diff --git a/spec/unit/recipes/default_spec.rb b/spec/unit/recipes/default_spec.rb index de56652b..a04b19fb 100644 --- a/spec/unit/recipes/default_spec.rb +++ b/spec/unit/recipes/default_spec.rb @@ -26,6 +26,44 @@ runner.converge(described_recipe) end + it 'installs the inspec gem' do + expect(chef_run).to install_chef_gem('inspec') + end + + it 'converges successfully' do + expect { chef_run }.to_not raise_error + end + end + + + context 'When an inspec gem version is specified ' do + let(:chef_run) do + ChefSpec::ServerRunner.new do |node| + node.override['audit']['inspec_version'] = '0.0.0' + end.converge(described_recipe) + end + + it 'installs the inspec gem with the correct version' do + expect(chef_run).to install_chef_gem('inspec').with(version: '0.0.0') + end + + it 'converges successfully' do + expect { chef_run }.to_not raise_error + end + end + + context 'When an inspec gem alternate source is specified ' do + let(:chef_run) do + ChefSpec::ServerRunner.new do |node| + node.override['audit']['inspec_gem_source'] = 'http://0.0.0.0:8080' + end.converge(described_recipe) + end + + it 'installs the inspec gem from the alternate source' do + expect(chef_run).to install_chef_gem('inspec').with(clear_sources: true) + expect(chef_run).to install_chef_gem('inspec').with(source: 'http://0.0.0.0:8080') + end + it 'converges successfully' do expect { chef_run }.to_not raise_error end