How to use version method of Inspec Package

Best Inspec_ruby code snippet using Inspec.version

inspec_gem.rb

Source:inspec_gem.rb Github

copy

Full Screen

1provides :inspec_gem2resource_name :inspec_gem3property :gem_name, String, name_property: true4property :version, String5property :source, String6default_action :install7action :install do8 # detect if installation is required9 compatible_version = compatible_with_client?(new_resource.version)10 installation_required = inspec_info.nil? || !new_resource.version.nil?11 # detect if the same version is already installed12 unless inspec_info.nil?13 installed_version = inspec_info.version.to_s14 Chef::Log.debug("Installed Chef-InSpec version: #{installed_version}")15 if new_resource.version == installed_version16 installation_required = false17 Chef::Log.info("inspec_gem: not installing Chef-InSpec. Requested version #{new_resource.version} already installed")18 return19 end20 end21 if installation_required && compatible_version22 Chef::Log.info("Installation of Chef-InSpec required: #{installation_required}")23 unless inspec_info.nil?24 converge_by 'uninstall all inspec and train gem versions' do25 uninstall_inspec_gem26 end27 end28 converge_by 'install given Chef-InSpec version' do29 install_inspec_gem(version: new_resource.version, source: new_resource.source)30 end31 elsif new_resource.version.nil?32 Chef::Log.info('inspec_gem: not installing Chef-InSpec. No Chef-Inspec version specified')33 elsif !compatible_version34 Chef::Log.warn("inspec_gem: not installing Chef-InSpec. Requested version #{new_resource.version} is not compatible with chef-client #{Chef::VERSION}")35 end36end37action_class do38 def install_inspec_gem(options)39 gem_source = options[:source]40 gem_version = options[:version]41 gem_version = nil if gem_version == 'latest'42 # use inspec-core for recent inspec versions43 gem_name = use_inspec_core?(gem_version) ? 'inspec-core' : 'inspec'44 chef_gem gem_name do45 version gem_version unless gem_version.nil?46 unless gem_source.nil?47 clear_sources true48 include_default_source false if respond_to?(:include_default_source)49 source gem_source50 end51 compile_time false52 action :install53 end54 chef_gem 'inspec-core-bin' do55 version gem_version unless gem_version.nil?56 unless gem_source.nil?57 clear_sources true58 include_default_source false if respond_to?(:include_default_source)59 source gem_source60 end61 compile_time false62 action :install63 only_if { need_inspec_core_bin?(gem_version) }64 end65 end66 def compatible_with_client?(gem_version)67 # No version specified so they will get the latest68 return true if gem_version.nil?69 if chef_gte_15?70 # Chef-15 can only run with the version of inspec-core and train-core that's being bundled with71 # It's pinned here: grep "inspec-" /opt/chef/bin/chef-client72 Chef::Log.warn('inspec_gem: Chef Infra Client >= 15 detected, can only use the embedded InSpec gem!!!')73 false74 else75 # min version required to run the audit handler76 Gem::Requirement.new(['>= 1.25.1']).satisfied_by?(Gem::Version.new(gem_version))77 end78 end79 def chef_gte_15?80 Gem::Requirement.new('>= 15').satisfied_by?(Gem::Version.new(Chef::VERSION))81 end82 def use_inspec_core?(gem_version)83 return true if gem_version.nil? # latest version84 Gem::Requirement.new('>= 2.1.67').satisfied_by?(Gem::Version.new(gem_version))85 end86 # Inspec 4+ does not include inspec binaries and requires an additional gem87 def need_inspec_core_bin?(gem_version)88 return true if gem_version.nil? # latest version89 Gem::Requirement.new('>= 4').satisfied_by?(Gem::Version.new(gem_version))90 end91 def uninstall_inspec_gem92 chef_gem 'remove all inspec versions' do93 package_name 'inspec'94 action :remove95 end96 chef_gem 'remove all inspec-core versions' do97 package_name 'inspec-core'98 action :remove99 end100 chef_gem 'remove all inspec-core-bin versions' do101 package_name 'inspec-core-bin'102 action :remove103 end104 chef_gem 'remove all train versions' do105 package_name 'train'106 action :remove107 end108 chef_gem 'remove all train-core versions' do109 package_name 'train-core'110 action :remove111 end112 end113 def inspec_info114 require 'rubygems'115 Gem::Specification.find { |s| %w(inspec inspec-core).include?(s.name) }116 rescue LoadError117 nil118 end119end...

Full Screen

Full Screen

reporter.rb

Source:reporter.rb Github

copy

Full Screen

...15 # Eeease of use here16 platform = mushy_report.platform17 profiles = mushy_report.profiles18 statistics = mushy_report.statistics19 version = mushy_report.version20 # Some pass/fail information21 test_results = profiles.map(&:controls).flatten.map(&:results).flatten.map(&:status)22 passed_tests = test_results.select { |text| text == "passed" }.count23 failed_tests = test_results.count - passed_tests24 percent_pass = 100.0 * passed_tests / test_results.count25 percent_fail = 100.0 - percent_pass26 # Detailed OS27 platform_arch = runner.backend.backend.os.arch28 platform_name = runner.backend.backend.os.title29 # Allow template-based settings30 template_config = config.fetch("template_config", {})31 # ... also can use all InSpec resources via "inspec_resource.NAME.PROPERTY"32 output(template.result(binding))33 end...

Full Screen

Full Screen

Rakefile

Source:Rakefile Github

copy

Full Screen

...25 end26end27task :changelog do28 # Automatically generate a changelog for this project. Only loaded if29 # the necessary gem is installed. By default its picking up the version from30 # inspec.yml. You can override that behavior with `rake changelog to=1.2.0`31 require 'yaml'32 metadata = YAML.load_file('inspec.yml')33 v = ENV['to'] || metadata['version']34 puts " * Generating changelog for version #{v}"35 require 'github_changelog_generator/task'36 GitHubChangelogGenerator::RakeTask.new :changelog do |config|37 config.future_release = v38 config.user = 'dev-sec'39 config.project = 'windows-patch-baseline'40 end41 Rake::Task[:changelog].execute42rescue LoadError43 puts '>>>>> GitHub Changelog Generator not loaded, omitting tasks'44end...

Full Screen

Full Screen

version

Using AI Code Generation

copy

Full Screen

1 it { should >= '1.0.0' }2 it { should >= '1.0.0' }3 it { should >= '1.0.0' }4 it { should >= '1.0.0' }5 it { should >= '1.0.0' }6 it { should >= '1.0.0' }7 it { should >= '1.0.0' }8 it { should >= '1.0.0' }9 it { should >= '1.0.0' }10 it { should >= '1.0.0' }

Full Screen

Full Screen

version

Using AI Code Generation

copy

Full Screen

1 describe file('/etc/passwd') do2 it { should exist }3 describe file('/etc/passwd') do4 it { should be_file }5 describe file('/etc/passwd') do6 it { should be_file }7 describe file('/etc/passwd') do8 it { should be_file }9 describe file('/etc/passwd') do10 it { should be_file }11 describe file('/etc/passwd') do12 it { should be_file }13 describe file('/etc/passwd') do14 it { should be_file }15 describe file('/etc/passwd') do16 it { should be_file }17 describe file('/etc/passwd') do18 it { should be_file }19 describe file('/etc/passwd') do20 it { should exist }

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