How to use supports_platform method of Inspec Package

Best Inspec_ruby code snippet using Inspec.supports_platform

profile.rb

Source:profile.rb Github

copy

Full Screen

...123 )124 @runner_context =125 options[:profile_context] ||126 Inspec::ProfileContext.for_profile(self, @backend)127 @supports_platform = metadata.supports_platform?(@backend)128 @supports_runtime = metadata.supports_runtime?129 end130 def name131 metadata.params[:name]132 end133 def version134 metadata.params[:version]135 end136 def writable?137 @writable138 end139 #140 # Is this profile is supported on the current platform of the141 # backend machine and the current inspec version.142 #143 # @returns [TrueClass, FalseClass]144 #145 def supported?146 supports_platform? && supports_runtime?147 end148 # We need to check if we're using a Mock'd backend for tests to function.149 # @returns [TrueClass, FalseClass]150 def supports_platform?151 if @supports_platform.nil?152 @supports_platform = metadata.supports_platform?(@backend)153 end154 if @backend.backend.class.to_s == 'Train::Transports::Mock::Connection'155 @supports_platform = true156 end157 @supports_platform158 end159 def supports_runtime?160 if @supports_runtime.nil?161 @supports_runtime = metadata.supports_runtime?162 end163 @supports_runtime164 end165 def params166 @params ||= load_params167 end168 def collect_tests(include_list = @controls)169 unless @tests_collected170 return unless supports_platform?171 locked_dependencies.each(&:collect_tests)172 tests.each do |path, content|173 next if content.nil? || content.empty?174 abs_path = source_reader.target.abs_path(path)175 @runner_context.load_control_file(content, abs_path, nil)176 end177 @tests_collected = true178 end179 filter_controls(@runner_context.all_rules, include_list)180 end181 def filter_controls(controls_array, include_list)182 return controls_array if include_list.nil? || include_list.empty?183 # Check for anything that might be a regex in the list, and make it official184 include_list.each_with_index do |inclusion, index|185 next if inclusion.is_a?(Regexp)186 # Insist the user wrap the regex in slashes to demarcate it as a regex187 next unless inclusion.start_with?('/') && inclusion.end_with?('/')188 inclusion = inclusion[1..-2] # Trim slashes189 begin190 re = Regexp.new(inclusion)191 include_list[index] = re192 rescue RegexpError => e193 warn "Ignoring unparseable regex '/#{inclusion}/' in --control CLI option: #{e.message}"194 include_list[index] = nil195 end196 end197 include_list.compact!198 controls_array.select do |c|199 id = ::Inspec::Rule.rule_id(c)200 include_list.any? do |inclusion|201 # Try to see if the inclusion is a regex, and if it matches202 inclusion == id || (inclusion.is_a?(Regexp) && inclusion =~ id)203 end204 end205 end206 def load_libraries207 return @runner_context if @libraries_loaded208 locked_dependencies.dep_list.each_with_index do |(_name, dep), i|209 d = dep.profile210 # this will force a dependent profile load so we are only going to add211 # this metadata if the parent profile is supported.212 if supports_platform? && !d.supports_platform?213 # since ruby 1.9 hashes are ordered so we can just use index values here214 metadata.dependencies[i][:status] = 'skipped'215 msg = "Skipping profile: '#{d.name}' on unsupported platform: '#{d.backend.platform.name}/#{d.backend.platform.release}'."216 metadata.dependencies[i][:skip_message] = msg217 next218 elsif metadata.dependencies[i]219 # Currently wrapper profiles will load all dependencies, and then we220 # load them again when we dive down. This needs to be re-done.221 metadata.dependencies[i][:status] = 'loaded'222 end223 c = d.load_libraries224 @runner_context.add_resources(c)225 end226 libs = libraries.map do |path, content|227 [content, path]228 end229 @runner_context.load_libraries(libs)230 @libraries_loaded = true231 @runner_context232 end233 def to_s234 "Inspec::Profile<#{name}>"235 end236 # return info using uncached params237 def info!238 info(load_params.dup)239 end240 def info(res = params.dup) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength241 # add information about the controls242 res[:controls] = res[:controls].map do |id, rule|243 next if id.to_s.empty?244 data = rule.dup245 data.delete(:checks)246 data[:impact] ||= 0.5247 data[:impact] = 1.0 if data[:impact] > 1.0248 data[:impact] = 0.0 if data[:impact] < 0.0249 data[:id] = id250 # if the code field is empty try and pull info from dependencies251 if data[:code].empty? && parent_profile.nil?252 locked_dependencies.dep_list.each do |_name, dep|253 profile = dep.profile254 code = Inspec::MethodSource.code_at(data[:source_location], profile.source_reader)255 data[:code] = code unless code.nil? || code.empty?256 break if !data[:code].empty?257 end258 end259 data260 end.compact261 # resolve hash structure in groups262 res[:groups] = res[:groups].map do |id, group|263 group[:id] = id264 group265 end266 # add information about the required inputs267 if res[:inputs].nil? || res[:inputs].empty?268 # convert to array for backwards compatability269 res[:inputs] = []270 else271 res[:inputs] = res[:inputs].values.map(&:to_hash)272 end273 res[:sha256] = sha256274 res[:parent_profile] = parent_profile unless parent_profile.nil?275 if !supports_platform?276 res[:status] = 'skipped'277 msg = "Skipping profile: '#{name}' on unsupported platform: '#{backend.platform.name}/#{backend.platform.release}'."278 res[:skip_message] = msg279 else280 res[:status] = 'loaded'281 end282 # convert legacy os-* supports to their platform counterpart283 if res[:supports] && !res[:supports].empty?284 res[:supports].each do |support|285 support[:"platform-family"] = support.delete(:"os-family") if support.key?(:"os-family")286 support[:"platform-name"] = support.delete(:"os-name") if support.key?(:"os-name")287 end288 end289 res...

Full Screen

Full Screen

metadata_test.rb

Source:metadata_test.rb Github

copy

Full Screen

...109 res.params[:supports].must_equal([{ release: nil }])110 end111 it 'load a profile with empty supports clause' do112 m = supports_meta(nil)113 m.supports_platform?(backend).must_equal true114 end115 it 'loads a profile which supports os ubuntu' do116 m = supports_meta({ 'os' => 'ubuntu' })117 m.supports_platform?(backend).must_equal true118 end119 it 'loads a profile which supports os name ubuntu' do120 m = supports_meta({ 'os-name' => 'ubuntu' })121 m.supports_platform?(backend).must_equal true122 end123 it 'loads a profile which supports os family linux' do124 m = supports_meta({ 'os-family' => 'linux' })125 m.supports_platform?(backend).must_equal true126 end127 it 'loads a profile which supports release 14.04' do128 m = supports_meta({ 'release' => '14.04' })129 m.supports_platform?(backend).must_equal true130 end131 it 'rejects a profile which supports release 12.04' do132 m = supports_meta({ 'release' => '12.04' })133 m.supports_platform?(backend).must_equal false134 end135 it 'loads a profile which supports ubuntu 14.04' do136 m = supports_meta({ 'os-name' => 'ubuntu', 'release' => '14.04' })137 m.supports_platform?(backend).must_equal true138 end139 it 'loads a profile which supports ubuntu 14.*' do140 m = supports_meta({ 'os-name' => 'ubuntu', 'release' => '14.*' })141 m.supports_platform?(backend).must_equal true142 end143 it 'rejects a profile which supports ubuntu 12.04' do144 m = supports_meta({ 'os-name' => 'ubuntu', 'release' => '12.04' })145 m.supports_platform?(backend).must_equal false146 end147 it 'rejects a profile which supports ubuntu 12.*' do148 m = supports_meta({ 'os-name' => 'ubuntu', 'release' => '12.*' })149 m.supports_platform?(backend).must_equal false150 end151 it 'loads a profile which supports ubuntu float 14.04 as parsed by yml' do152 m = supports_meta({ 'os-name' => 'ubuntu', 'release' => 14.04 })153 m.supports_platform?(backend).must_equal true154 end155 it 'reject unsupported os' do156 m = supports_meta({ 'os-name' => 'windows' })157 m.supports_platform?(backend).must_equal false158 end159 it 'loads a profile which supports multiple families' do160 m = supports_meta([161 { 'os-family' => 'windows' },162 { 'os-family' => 'unix' }163 ])164 m.supports_platform?(backend).must_equal true165 end166 it 'loads a profile which supports multiple names' do167 m = supports_meta([168 { 'os-family' => 'windows', 'os-name' => 'windows_2000'},169 { 'os-family' => 'unix', 'os-name' => 'ubuntu' }170 ])171 m.supports_platform?(backend).must_equal true172 end173 it 'reject a profile which supports multiple families' do174 m = supports_meta([175 { 'os-family' => 'windows' },176 { 'os-family' => 'redhat' }177 ])178 m.supports_platform?(backend).must_equal false179 end180 end181 describe 'testing the supported runtime' do182 let(:current_version) { Inspec::VERSION }183 let(:next_version) { Gem::Version.new(current_version).bump.to_s }184 def version_meta(params)185 res = Inspec::Metadata.from_yaml('mock', "---", nil, logger)186 res.params[:inspec_version] = params187 Inspec::Metadata.finalize(res, 'mock', empty_options, logger)188 res189 end190 it 'returns true on testing the current version' do191 m = version_meta(current_version)192 m.supports_runtime?.must_equal true...

Full Screen

Full Screen

supports_platform

Using AI Code Generation

copy

Full Screen

1 title '1.1 Ensure a separate partition for containers has been created (Scored)'2 supports_platform?('centos', 'redhat', 'fedora')3 describe mount('/') do4 it { should be_mounted }5 title '1.2 Ensure only trusted users are allowed to control Docker daemon (Scored)'6 desc 'Docker daemon by default listens on a Unix socket and any user on the system with access to the socket can control the daemon. Unix socket does not provide authentication. It is therefore important to configure Docker daemon to use TLS authentication to ensure that only trusted users can control your Docker daemon.'7 supports_platform?('centos', 'redhat', 'fedora')8 describe mount('/') do9 it { should be_mounted }10 title '1.3 Ensure auditing is configured for the docker daemon (Scored)'

Full Screen

Full Screen

supports_platform

Using AI Code Generation

copy

Full Screen

1 it { should support_platform('ubuntu') }2 it { should support_platform('centos') }3 it { should support_platform?('ubuntu') }4 it { should support_platform?('centos') }5 it { should_not support_platform?('ubuntu') }6 it { should_not support_platform?('centos') }7 it { should_not support_platform?('ubuntu') }8 it { should support_platform?('centos') }9 it { should support_platform?('ubuntu') }10 it { should_not support_platform?('centos') }11 it { should_not support_platform?('ubuntu') }12 it { should_not support_platform?('centos') }13 it { should_not support_platform?('ubuntu') }14 it { should_not support_platform?('centos') }

Full Screen

Full Screen

supports_platform

Using AI Code Generation

copy

Full Screen

1 describe inspec.supports_platform?('redhat') do2 it { should eq true }3 describe inspec.supports_platform?('redhat') do4 it { should eq true }5 describe inspec.supports_platform?('redhat') do6 it { should eq true }7 describe inspec.supports_platform?('redhat') do8 it { should eq true }9 describe inspec.supports_platform?('redhat') do10 it { should eq true }

Full Screen

Full Screen

supports_platform

Using AI Code Generation

copy

Full Screen

1 title '1.1 Ensure a separate partition for containers has been created (Scored)'2 supports_platform?('centos', 'redhat', 'fedora')3 describe mount('/') do4 it { should be_mounted }5 title '1.2 Ensure only trusted users are allowed to control Docker daemon (Scored)'6 desc 'Docker daemon by default listens on a Unix socket and any user on the system with access to the socket can control the daemon. Unix socket does not provide authentication. It is therefore important to configure Docker daemon to use TLS authentication to ensure that only trusted users can control your Docker daemon.'7 supports_platform?('centos', 'redhat', 'fedora')8 describe mount('/') do9 it { should be_mounted }10 title '1.3 Ensure auditing is configured for the docker daemon (Scored)'

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