Skip to content

Commit

Permalink
Merge pull request #84 from chef-cookbooks/minor_fixes
Browse files Browse the repository at this point in the history
Minor fixes and changes
  • Loading branch information
chris-rock authored Aug 23, 2016
2 parents dbbb3f5 + ed8047f commit a36cec1
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 54 deletions.
1 change: 0 additions & 1 deletion .kitchen.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
driver:
name: dokken
chef_version: 12.7.2
privileged: true # because Docker and SystemD/Upstart

transport:
Expand Down
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
source 'https://rubygems.org'

gem 'chef', '>= 12.0'
gem 'chef', '>= 12.5.1'

group :style do
gem 'foodcritic', '~> 6.0'
gem 'rubocop', '~> 0.36.0'
gem 'foodcritic', '~> 7.0'
gem 'cookstyle'
end

group :test do
Expand Down
87 changes: 55 additions & 32 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,48 +1,71 @@
#!/usr/bin/env rake

# Import other external rake tasks
Dir.glob('tasks/*.rake').each { |r| import r }
# Style tests. cookstyle (rubocop) and Foodcritic
namespace :style do
begin
require 'cookstyle'
require 'rubocop/rake_task'

require 'foodcritic'
require 'rake/clean'
require 'rspec/core/rake_task'
require 'rubocop/rake_task'

CLEAN.include %w(.kitchen/ coverage/ doc/)
CLOBBER.include %w(Berksfile.lock Gemfile.lock .yardoc/)

# Default tasks to run when executing `rake`
task default: %w(lint)
desc 'Run Ruby style checks'
RuboCop::RakeTask.new(:ruby)
rescue LoadError => e
puts ">>> Gem load error: #{e}, omitting style:ruby" unless ENV['CI']
end

# Style tests. Rubocop and Foodcritic
namespace :lint do
desc 'Run Ruby style checks'
RuboCop::RakeTask.new(:ruby)
begin
require 'foodcritic'

desc 'Run Chef style checks'
FoodCritic::Rake::LintTask.new(:chef) do |t|
t.options = { fail_tags: ['any'] }
desc 'Run Chef style checks'
FoodCritic::Rake::LintTask.new(:chef) do |t|
t.options = {
fail_tags: ['any'],
progress: true
}
end
rescue LoadError
puts ">>> Gem load error: #{e}, omitting style:chef" unless ENV['CI']
end
end

desc 'Run all style checks'
task lint: ['lint:chef', 'lint:ruby']
task style: ['style:chef', 'style:ruby']

# ChefSpec
begin
require 'rspec/core/rake_task'

# Rspec and ChefSpec
desc 'Run ChefSpec examples'
RSpec::Core::RakeTask.new(:spec) do |t|
t.verbose = false
desc 'Run ChefSpec examples'
RSpec::Core::RakeTask.new(:spec)
rescue LoadError => e
puts ">>> Gem load error: #{e}, omitting spec" unless ENV['CI']
end

desc 'Find notes in code'
task :notes do
puts `egrep --exclude=Rakefile --exclude=*.log -n -r -i '(TODO|FIXME|OPTIMIZE)' .`
# Integration tests. Kitchen.ci
namespace :integration do
begin
require 'kitchen/rake_tasks'

desc 'Run kitchen integration tests'
Kitchen::RakeTasks.new
rescue LoadError => e
puts ">>> Gem load error: #{e}, omitting #{task.name}" unless ENV['CI']
rescue Kitchen::UserError => e
puts ">>> Test Kitchen error: #{e}" unless ENV['CI']
rescue Kitchen::UserError => e
puts ">>> Test Kitchen error: #{e}" unless ENV['CI']
end
end

namespace :test do
task :integration do
concurrency = ENV['CONCURRENCY'] || 1
path = File.join(File.dirname(__FILE__), 'test', 'integration')
sh('sh', '-c', "bundle exec kitchen test -c #{concurrency}")
namespace :supermarket do
begin
require 'stove/rake_task'

desc 'Publish cookbook to Supermarket with Stove'
Stove::RakeTask.new
rescue LoadError => e
puts ">>> Gem load error: #{e}, omitting #{task.name}" unless ENV['CI']
end
end

# Default
task default: %w(style spec)
6 changes: 3 additions & 3 deletions libraries/collector_classes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Collector
#
# Used to send inspec reports to Chef Visibility via the data_collector service
#
class ChefVisibility # rubocop:disable Metrics/ClassLength
class ChefVisibility
@entity_uuid = nil
@run_id = nil
@blob = []
Expand Down Expand Up @@ -111,7 +111,7 @@ def count_controls(profiles)
end

# Return a json string containing the inspec report to be sent to the data_collector
def enriched_report # rubocop:disable Metrics/AbcSize
def enriched_report
return nil unless @blob.is_a?(Hash) && @blob[:reports].is_a?(Hash)
final_report = {}
node_name = @blob[:node] # ~FC001, ~FC019, ~FC039
Expand Down Expand Up @@ -152,7 +152,7 @@ def enriched_report # rubocop:disable Metrics/AbcSize
end

# Method used in order to send the inspec report to the data_collector server
def send_report # rubocop:disable PerceivedComplexity, Metrics/CyclomaticComplexity
def send_report
unless @entity_uuid && @run_id
Chef::Log.warn "entity_uuid(#{@entity_uuid}) or run_id(#{@run_id}) can't be nil, not sending report..."
return false
Expand Down
2 changes: 1 addition & 1 deletion libraries/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def handle_http_error_code(code)
end
msg = "Received HTTP error #{code}. Please verify the authentication (e.g. token) is set properly."
Chef::Log.error msg
fail msg if @raise_if_unreachable
raise msg if @raise_if_unreachable
end

#rubocop:disable all
Expand Down
4 changes: 2 additions & 2 deletions libraries/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# `compliance_profile` custom resource to collect and run Chef Compliance
# profiles
class ComplianceProfile < Chef::Resource # rubocop:disable Metrics/ClassLength
class ComplianceProfile < Chef::Resource
include ComplianceHelpers
use_automatic_resource_name

Expand Down Expand Up @@ -133,7 +133,7 @@ class ComplianceProfile < Chef::Resource # rubocop:disable Metrics/ClassLength
supported_schemes = %w{http https supermarket compliance chefserver}
if !supported_schemes.include?(URI(path).scheme) && !::File.exist?(path)
Chef::Log.warn "No such path! Skipping: #{path}"
fail "Aborting since profile is not present here: #{path}" if run_context.node['audit']['fail_if_not_present']
raise "Aborting since profile is not present here: #{path}" if run_context.node['audit']['fail_if_not_present']
return
end

Expand Down
2 changes: 1 addition & 1 deletion libraries/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class ComplianceReport < Chef::Resource
Chef::Log.warn "#{collector} is not a supported inspec report collector"
end

fail "#{total_failed} audits have failed. Aborting chef-client run." if total_failed > 0 && node['audit']['fail_if_any_audits_failed']
raise "#{total_failed} audits have failed. Aborting chef-client run." if total_failed > 0 && node['audit']['fail_if_any_audits_failed']
end
end

Expand Down
4 changes: 2 additions & 2 deletions metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
maintainer 'Chef Software, Inc.'
maintainer_email 'cookbooks@chef.io'
license 'Apache 2.0'
description 'Allows for fetching and executing compliance profiles, and '\
'reporting its results'
description 'Allows for fetching and executing compliance profiles, and reporting its results'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '0.14.2'

source_url 'https://github.com/chef-cookbooks/audit'
Expand Down
2 changes: 1 addition & 1 deletion recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
else
next if value == false
end
fail "Invalid profile name '#{owner_profile}'. "\
raise "Invalid profile name '#{owner_profile}'. "\
"Must contain /, e.g. 'john/ssh'" if owner_profile !~ %r{\/}
o, p = owner_profile.split('/').last(2)

Expand Down
8 changes: 0 additions & 8 deletions travis.yml

This file was deleted.

0 comments on commit a36cec1

Please sign in to comment.