mirror of
https://github.com/inspec/inspec
synced 2024-11-27 23:20:33 +00:00
49 lines
1.6 KiB
Ruby
49 lines
1.6 KiB
Ruby
# 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|
|
|
m = %r{^#{Supermarket::API.supermarket_url}/api/v1/tools/(?<slug>[\w-]+)(/)?$}.match(p['tool'])
|
|
li("#{p['tool_owner']}/#{m[:slug]}")
|
|
}
|
|
end
|
|
|
|
desc 'exec PROFILE', 'execute a Supermarket profile'
|
|
option :id, type: :string,
|
|
desc: 'Attach a profile ID to all test results'
|
|
target_options
|
|
option :format, type: :string
|
|
def exec(tests)
|
|
# iterate over tests and add compliance scheme
|
|
tests = tests.map { |t| 'supermarket://' + t }
|
|
|
|
# execute profile from inspec exec implementation
|
|
diagnose
|
|
run_tests(tests, opts)
|
|
end
|
|
|
|
desc 'info PROFILE', 'display Supermarket profile details'
|
|
def info(profile)
|
|
info = Supermarket::API.info(profile)
|
|
|
|
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', {})
|
|
end
|