Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding support for alternate gem source #146

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 2 additions & 0 deletions recipes/default.rb
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 2 additions & 0 deletions recipes/upload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
38 changes: 38 additions & 0 deletions spec/unit/recipes/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down