How to use help method of Inspec Package

Best Inspec_ruby code snippet using Inspec.help

plugin_cli.rb

Source:plugin_cli.rb Github

copy

Full Screen

2require 'roo'3require_relative '../utilities/inspec_util'4require_relative '../utilities/csv_util'5module InspecTools6 autoload :Help, 'inspec_tools/help'7 autoload :Command, 'inspec_tools/command'8 autoload :XCCDF, 'inspec_tools/xccdf'9 autoload :PDF, 'inspec_tools/pdf'10 autoload :CSVTool, 'inspec_tools/csv'11 autoload :CKL, 'inspec_tools/ckl'12 autoload :Inspec, 'inspec_tools/inspec'13 autoload :Summary, 'inspec_tools/summary'14 autoload :XLSXTool, 'inspec_tools/xlsx_tool'15 autoload :GenerateMap, 'inspec_tools/generate_map'16end17module InspecPlugins18 module InspecToolsPlugin19 class CliCommand < Inspec.plugin(2, :cli_command)20 POSSIBLE_LOG_LEVELS = %w{debug info warn error fatal}.freeze21 class_option :log_directory, type: :string, aliases: :l, desc: 'Provide log location'22 class_option :log_level, type: :string, desc: "Set the logging level: #{POSSIBLE_LOG_LEVELS}"23 subcommand_desc 'tools [COMMAND]', 'Runs inspec_tools commands through Inspec'24 desc 'xccdf2inspec', 'xccdf2inspec translates an xccdf file to an inspec profile'25 long_desc InspecTools::Help.text(:xccdf2inspec)26 option :xccdf, required: true, aliases: '-x'27 option :attributes, required: false, aliases: '-a'28 option :output, required: false, aliases: '-o', default: 'profile'29 option :format, required: false, aliases: '-f', enum: %w{ruby hash}, default: 'ruby'30 option :separate_files, required: false, type: :boolean, default: true, aliases: '-s'31 option :replace_tags, type: :array, required: false, aliases: '-r'32 option :metadata, required: false, aliases: '-m'33 option :control_id, required: false, enum: %w{ruleID vulnID}, aliases: '-c', default: 'vulnID'34 def xccdf2inspec35 xccdf = InspecTools::XCCDF.new(File.read(options[:xccdf]), options[:control_id] == 'vulnID', options[:replace_tags])36 profile = xccdf.to_inspec37 if !options[:metadata].nil?38 xccdf.inject_metadata(File.read(options[:metadata]))39 end40 Utils::InspecUtil.unpack_inspec_json(options[:output], profile, options[:separate_files], options[:format])41 if !options[:attributes].nil?42 attributes = xccdf.to_attributes43 File.write(options[:attributes], YAML.dump(attributes))44 end45 end46 desc 'inspec2xccdf', 'inspec2xccdf translates an inspec profile and attributes files to an xccdf file'47 long_desc InspecTools::Help.text(:inspec2xccdf)48 option :inspec_json, required: true, aliases: '-j',49 desc: 'path to InSpec JSON file created'50 option :attributes, required: true, aliases: '-a',51 desc: 'path to yml file that provides the required attributes for the XCCDF document. These attributes are parts of XCCDF document which do not fit into the InSpec schema.'52 option :output, required: true, aliases: '-o',53 desc: 'name or path to create the XCCDF and title to give the XCCDF'54 option :metadata, required: false, type: :string, aliases: '-m',55 desc: 'path to JSON file with additional host metadata for the XCCDF file'56 def inspec2xccdf57 io = File.open(options[:inspec_json], 'rb')58 io.set_encoding_by_bom59 metadata = options[:metadata] ? JSON.parse(File.read(options[:metadata])) : {}60 inspec_tool = InspecTools::Inspec.new(io.read, metadata)61 attr_hsh = YAML.load_file(options[:attributes])62 xccdf = inspec_tool.to_xccdf(attr_hsh)63 File.write(options[:output], xccdf)64 end65 desc 'csv2inspec', 'csv2inspec translates CSV to Inspec controls using a mapping file'66 long_desc InspecTools::Help.text(:csv2inspec)67 option :csv, required: true, aliases: '-c'68 option :mapping, required: true, aliases: '-m'69 option :verbose, required: false, type: :boolean, aliases: '-V'70 option :output, required: false, aliases: '-o', default: 'profile'71 option :format, required: false, aliases: '-f', enum: %w{ruby hash}, default: 'ruby'72 option :separate_files, required: false, type: :boolean, default: true, aliases: '-s'73 option :control_name_prefix, required: false, type: :string, aliases: '-p'74 def csv2inspec75 csv = CSV.read(options[:csv], encoding: 'ISO8859-1')76 mapping = YAML.load_file(options[:mapping])77 profile = InspecTools::CSVTool.new(csv, mapping, options[:csv].split('/')[-1].split('.')[0], options[:verbose]).to_inspec(control_name_prefix: options[:control_name_prefix])78 Utils::InspecUtil.unpack_inspec_json(options[:output], profile, options[:separate_files], options[:format])79 end80 desc 'xlsx2inspec', 'xlsx2inspec translates CIS XLSX to Inspec controls using a mapping file'81 long_desc InspecTools::Help.text(:xlsx2inspec)82 option :xlsx, required: true, aliases: '-x'83 option :mapping, required: true, aliases: '-m'84 option :control_name_prefix, required: true, aliases: '-p'85 option :verbose, required: false, type: :boolean, aliases: '-V'86 option :output, required: false, aliases: '-o', default: 'profile'87 option :format, required: false, aliases: '-f', enum: %w{ruby hash}, default: 'ruby'88 option :separate_files, required: false, type: :boolean, default: true, aliases: '-s'89 def xlsx2inspec90 xlsx = Roo::Spreadsheet.open(options[:xlsx])91 mapping = YAML.load_file(options[:mapping])92 profile = InspecTools::XLSXTool.new(xlsx, mapping, options[:xlsx].split('/')[-1].split('.')[0], options[:verbose]).to_inspec(options[:control_name_prefix])93 Utils::InspecUtil.unpack_inspec_json(options[:output], profile, options[:separate_files], options[:format])94 end95 desc 'inspec2csv', 'inspec2csv translates Inspec controls to CSV'96 long_desc InspecTools::Help.text(:inspec2csv)97 option :inspec_json, required: true, aliases: '-j'98 option :output, required: true, aliases: '-o'99 option :verbose, required: false, type: :boolean, aliases: '-V'100 def inspec2csv101 csv = InspecTools::Inspec.new(File.read(options[:inspec_json])).to_csv102 Utils::CSVUtil.unpack_csv(csv, options[:output])103 end104 desc 'inspec2ckl', 'inspec2ckl translates an Inspec results JSON file to a Checklist file'105 long_desc InspecTools::Help.text(:inspec2ckl)106 option :inspec_json, required: true, aliases: '-j',107 desc: 'path to InSpec results JSON file'108 option :output, required: true, aliases: '-o',109 desc: 'path to output checklist file'110 option :metadata, required: false, aliases: '-m',111 desc: 'path to JSON file with additional metadata for the Checklist file'112 option :verbose, type: :boolean, aliases: '-V'113 def inspec2ckl114 inspec_tools =115 if options[:metadata].nil?116 InspecTools::Inspec.new(File.read(options[:inspec_json]))117 else118 InspecTools::Inspec.new(File.read(options[:inspec_json]), JSON.parse(File.read(options[:metadata])))119 end120 File.write(options[:output], inspec_tools.to_ckl)121 end122 desc 'pdf2inspec', 'pdf2inspec translates a PDF Security Control Speficication to Inspec Security Profile'123 long_desc InspecTools::Help.text(:pdf2inspec)124 option :pdf, required: true, aliases: '-p'125 option :output, required: false, aliases: '-o', default: 'profile'126 option :debug, required: false, aliases: '-d', type: :boolean, default: false127 option :format, required: false, aliases: '-f', enum: %w{ruby hash}, default: 'ruby'128 option :separate_files, required: false, type: :boolean, default: true, aliases: '-s'129 def pdf2inspec130 pdf = File.open(options[:pdf])131 profile = InspecTools::PDF.new(pdf, options[:output], options[:debug]).to_inspec132 Utils::InspecUtil.unpack_inspec_json(options[:output], profile, options[:separate_files], options[:format])133 end134 desc 'generate_map', 'Generates mapping template from CSV to Inspec Controls'135 def generate_map136 generator = InspecTools::GenerateMap.new137 generator.generate_example('mapping.yml')138 end139 desc 'generate_ckl_metadata', 'Generate metadata file that can be passed to inspec2ckl'140 def generate_ckl_metadata141 metadata = {}142 metadata['benchmark'] = {}143 print('STIG ID: ')144 metadata['stigid'] = $stdin.gets.chomp145 print('Role: ')146 metadata['role'] = $stdin.gets.chomp147 print('Type: ')148 metadata['type'] = $stdin.gets.chomp149 print('Hostname: ')150 metadata['hostname'] = $stdin.gets.chomp151 print('IP Address: ')152 metadata['ip'] = $stdin.gets.chomp153 print('MAC Address: ')154 metadata['mac'] = $stdin.gets.chomp155 print('FQDN: ')156 metadata['fqdn'] = $stdin.gets.chomp157 print('Tech Area: ')158 metadata['tech_area'] = $stdin.gets.chomp159 print('Target Key: ')160 metadata['target_key'] = $stdin.gets.chomp161 print('Web or Database: ')162 metadata['web_or_database'] = $stdin.gets.chomp163 print('Web DB Site: ')164 metadata['web_db_site'] = $stdin.gets.chomp165 print('Web DB Instance: ')166 metadata['web_db_instance'] = $stdin.gets.chomp167 print('Benchmark title: ')168 metadata['benchmark']['title'] = $stdin.gets.chomp169 print('Benchmark version: ')170 metadata['benchmark']['version'] = $stdin.gets.chomp171 print('Benchmark revision/release information: ')172 metadata['benchmark']['plaintext'] = $stdin.gets.chomp173 recursive_compact =174 proc do |_k, value|175 value.delete_if(&recursive_compact) if value.is_a?(Hash)176 value.empty?177 end178 metadata.delete_if(&recursive_compact)179 File.open('metadata.json', 'w') do |f|180 f.write(metadata.to_json)181 end182 end183 desc 'generate_inspec_metadata', 'Generate mapping file that can be passed to xccdf2inspec'184 def generate_inspec_metadata185 metadata = {}186 print('Maintainer: ')187 metadata['maintainer'] = $stdin.gets.chomp188 print('Copyright: ')189 metadata['copyright'] = $stdin.gets.chomp190 print('Copyright Email: ')191 metadata['copyright_email'] = $stdin.gets.chomp192 print('License: ')193 metadata['license'] = $stdin.gets.chomp194 print('Version: ')195 metadata['version'] = $stdin.gets.chomp196 metadata.delete_if { |_key, value| value.empty? }197 File.open('metadata.json', 'w') do |f|198 f.write(metadata.to_json)199 end200 end201 desc 'summary', 'summary parses an inspec results json to create a summary json'202 long_desc InspecTools::Help.text(:summary)203 option :inspec_json, required: true, aliases: '-j'204 option :json_full, type: :boolean, required: false, aliases: '-f'205 option :json_counts, type: :boolean, required: false, aliases: '-k'206 option :threshold_file, required: false, aliases: '-t'207 option :threshold_inline, required: false, aliases: '-i'208 def summary209 summary = InspecTools::Summary.new(options: options)210 summary.output_summary211 end212 desc 'compliance', 'compliance parses an inspec results json to check if the compliance level meets a specified threshold'213 long_desc InspecTools::Help.text(:compliance)214 option :inspec_json, required: true, aliases: '-j'215 option :threshold_file, required: false, aliases: '-f'216 option :threshold_inline, required: false, aliases: '-i'217 def compliance218 compliance = InspecTools::Summary.new(options: options)219 compliance.results_meet_threshold? ? exit(0) : exit(1)220 end221 end222 end223end224#=====================================================================#225# Pre-Flight Code226#=====================================================================#227help_commands = ['-h', '--help', 'help']228log_commands = ['-l', '--log-directory']229version_commands = ['-v', '--version', 'version']230#---------------------------------------------------------------------#231# Adjustments for non-required version commands232#---------------------------------------------------------------------#233unless (version_commands & ARGV).empty?234 puts InspecTools::VERSION235 exit 0236end237#---------------------------------------------------------------------#238# Adjustments for non-required log-directory239#---------------------------------------------------------------------#240ARGV.push("--log-directory=#{Dir.pwd}/logs") if (log_commands & ARGV).empty? && (help_commands & ARGV).empty?241# Push help to front of command so thor recognizes subcommands are called with help242if help_commands.any? { |cmd| ARGV.include? cmd }243 help_commands.each do |cmd|244 if (match = ARGV.delete(cmd))245 ARGV.unshift match246 end247 end248end...

Full Screen

Full Screen

cli.rb

Source:cli.rb Github

copy

Full Screen

...34 myfile = File.new('mapping.yml', 'w')35 myfile.puts template36 myfile.close37 end38 map %w{--help -h} => :help39 desc 'help', 'Help for using pdf2inspec'40 def help41 puts "\tpdf2inspec translates a PDF Secuirty Profile to Inspec controls\n\n"42 puts "\t-f --pdf : Path and file of the PDF you would like to process"43 puts "\t-n --name : The name for your new InSpec profile"44 puts "\t-x --excl : The CIS to NIST mapping Excel file"45 puts "\t-d --debug : (boolean) Turns on / off debug data for parsing"46 puts "\nexample: ./pdf2inspec exec --pdf secureConfigruation.pdf --excl myControlMap.xls --name my_inspec_profile\n\n"47 puts "\nexample: ./pdf2inspec exec -f secureConfigruation.pdf -x myControlMap.xls -n my_inspec_profile\n\n --debug"48 end49 map %w{--version -v} => :print_version50 desc '--version, -v', "print's csv2inspec version"51 def print_version52 puts Pdf2inspec::VERSION53 end54end...

Full Screen

Full Screen

plugin.rb

Source:plugin.rb Github

copy

Full Screen

...9 plugin_name :'inspec-iggy'10 cli_command :terraform do11 # Calling this hook doesn't mean iggy is being executed - just that we12 # should be ready to do so. So, load the file that defines the functionality.13 # For example, InSpec will activate this hook when `inspec help` is14 # executed, so that this plugin's usage message will be included in the help.15 require "inspec-iggy/terraform/cli_command"16 # Having loaded our functionality, return a class that will let the17 # CLI engine tap into it.18 InspecPlugins::Iggy::Terraform::CliCommand19 end20 cli_command :cloudformation do21 require "inspec-iggy/cloudformation/cli_command"22 InspecPlugins::Iggy::CloudFormation::CliCommand23 end24 cli_command :iggy do25 require "inspec-iggy/iggy_cli_command"26 InspecPlugins::Iggy::CliCommand27 end28 end...

Full Screen

Full Screen

help

Using AI Code Generation

copy

Full Screen

1 describe command('inspec help') do2 its('stdout') { should match /InSpec is a tool for executing tests locally or in the cloud/ }3 its('exit_status') { should eq 0 }4 describe command('inspec help') do5 its('stdout') { should match /InSpec is a tool for executing tests locally or in the cloud/ }6 its('exit_status') { should eq 0 }7 describe command('inspec help') do8 its('stdout') { should match /InSpec is a tool for executing tests locally or in the cloud/ }9 its('exit_status') { should eq 0 }10 describe command('inspec help') do11 its('stdout') { should match /InSpec is a tool for executing tests locally or in the cloud/ }12 its('exit_status') { should eq 0 }13 describe command('inspec help') do14 its('stdout') { should match /InSpec is a tool for executing tests locally or in the cloud/ }15 its('exit_status') { should eq 0 }16 describe command('inspec help') do17 its('stdout') { should match /InSpec is a tool for executing tests locally or in the cloud/ }18 its('exit_status') { should eq 0 }19 describe command('inspec help') do20 its('stdout') { should match /InSpec is a tool for executing tests locally

Full Screen

Full Screen

help

Using AI Code Generation

copy

Full Screen

1 expect(inspec).to_not receive(:help)2 expect(inspec).to receive(:help)3 expect(inspec).to receive(:help)4 expect(inspec).to receive(:help)5 expect(inspec).to receive(:help)6 expect(inspec).to receive(:help)7 expect(inspec).to receive(:help)8 expect(inspec).to receive(:help)9 expect(inspec).to receive(:help)10 expect(inspec).to receive(:help)

Full Screen

Full Screen

help

Using AI Code Generation

copy

Full Screen

1 it { should respond_to :help }2 it { should respond_to :help }3 it { should respond_to :help }4 it { should respond_to :help }5 it { should respond_to :help }6 it { should respond_to :help }7 it { should respond_to :help }8 it { should respond_to :help }9 it { should respond_to :help }10 it { should respond_to :help }11 it { should respond_to :help }

Full Screen

Full Screen

help

Using AI Code Generation

copy

Full Screen

1puts Inspec.help('command')2puts Inspec.help('Inspec::Resource')3puts Inspec.help('Inspec::Resource', 'command')4puts Inspec.help('Inspec::Resource', 'command')5puts Inspec.help('Inspec::Resource', 'command', options: 'options')6puts Inspec.help('Inspec::Resource', 'command', options: 'options')7puts Inspec.help('Inspec::Resource', 'command', options: 'options')8puts Inspec.help('Inspec::Resource', 'command', options: 'options')9puts Inspec.help('Inspec::Resource', 'command', options: 'options')10puts Inspec.help('Inspec::Resource', 'command', options: 'options')11puts Inspec.help('Inspec::Resource', 'command', options: 'options')12puts Inspec.help('Inspec::Resource', 'command', options: 'options')13puts Inspec.help('Inspec::Resource', 'command', options: 'options')14puts Inspec.help('Inspec::Resource', 'command', options: 'options')15puts Inspec.help('Inspec::Resource', 'command', options: 'options')

Full Screen

Full Screen

help

Using AI Code Generation

copy

Full Screen

1 it { should exist }2 its('help') { should match /inspec exec/ }3 it { should exist }4 its('help') { should match /inspec shell/ }5 it { should exist }6 its('help') { should match /inspec check/ }7 it { should exist }8 its('help') { should match /inspec archive/ }9 it { should exist }10 its('help') { should match /inspec json/ }11 it { should exist }12 its('help') { should match /inspec supermarket/ }13 it { should exist }14 its('help') { should match /inspec version/ }15 it { should exist }16 its('help') { should match /inspec env/ }17 it { should exist }18 its('help') { should match /inspec detect/ }19 it { should exist }20 its('help') { should match /inspec init/ }21 it { should exist }22 its('help') { should match /inspec compliance/ }

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Inspec_ruby automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful