inspec/lib/bundles/inspec-supermarket/cli.rb

57 lines
1.7 KiB
Ruby
Raw Normal View History

2016-02-08 19:06:07 +00:00
# encoding: utf-8
# author: Christoph Hartmann
# author: Dominik Richter
module Supermarket
class SupermarketCLI < Inspec::BaseCLI
namespace 'supermarket'
desc 'profiles', 'list all available profiles in Chef Supermarket'
def profiles
# display profiles in format user/profile
supermarket_profiles = Supermarket::API.profiles
headline('Available profiles:')
supermarket_profiles.each { |p|
2016-03-01 12:26:36 +00:00
li("#{p['tool_owner']}/#{p['slug']}")
2016-02-08 19:06:07 +00:00
}
end
desc 'exec PROFILE', 'execute a Supermarket profile'
2016-03-06 14:07:12 +00:00
exec_options
2016-03-01 12:26:36 +00:00
def exec(*tests)
2016-02-08 19:06:07 +00:00
# iterate over tests and add compliance scheme
tests = tests.map { |t| 'supermarket://' + t }
# execute profile from inspec exec implementation
diagnose
run_tests(tests, opts)
2016-02-08 19:06:07 +00:00
end
desc 'info PROFILE', 'display Supermarket profile details'
2016-02-08 19:06:07 +00:00
def info(profile)
2016-03-01 12:26:36 +00:00
# check that the profile is available
supermarket_profiles = Supermarket::API.profiles
found = supermarket_profiles.select { |p|
"#{p['tool_owner']}/#{p['slug']}" == profile
}
2016-02-08 19:06:07 +00:00
2016-03-01 12:26:36 +00:00
if found.length == 0
puts "#{mark_text(profile)} is not available on Supermarket"
return
end
# load details for the specific profile
info = Supermarket::API.info(profile)
2016-02-08 19:06:07 +00:00
puts "#{mark_text('name: ')} #{info['slug']}"
puts "#{mark_text('owner:')} #{info['owner']}"
puts "#{mark_text('url: ')} #{info['source_url']}"
puts
puts "#{mark_text('description: ')} #{info['description']}"
end
end
# register the subcommand to Inspec CLI registry
Inspec::Plugins::CLI.add_subcommand(SupermarketCLI, 'supermarket', 'supermarket SUBCOMMAND ...', 'Supermarket commands', {})
2016-02-08 19:06:07 +00:00
end