How to use control_eval_context method of Inspec Package

Best Inspec_ruby code snippet using Inspec.control_eval_context

profile_context.rb

Source:profile_context.rb Github

copy

Full Screen

...4require 'inspec/log'5require 'inspec/rule'6require 'inspec/resource'7require 'inspec/library_eval_context'8require 'inspec/control_eval_context'9require 'inspec/require_loader'10require 'securerandom'11require 'inspec/objects/input'12module Inspec13 class ProfileContext14 def self.for_profile(profile, backend)15 new(profile.name, backend, { 'profile' => profile, 'check_mode' => profile.check_mode })16 end17 attr_reader :backend, :profile_name, :profile_id, :resource_registry18 attr_accessor :rules19 def initialize(profile_id, backend, conf)20 if backend.nil?21 raise 'ProfileContext is initiated with a backend == nil. ' \22 'This is a backend error which must be fixed upstream.'23 end24 @profile_id = profile_id25 @backend = backend26 @conf = conf.dup27 @profile_name = @conf['profile'].profile_name || @profile_id if @conf['profile']28 @skip_only_if_eval = @conf['check_mode']29 @rules = {}30 @control_subcontexts = []31 @lib_subcontexts = []32 @require_loader = ::Inspec::RequireLoader.new33 Inspec::InputRegistry.register_profile_alias(@profile_id, @profile_name) if @profile_id != @profile_name34 # TODO: consider polling input source plugins; this is a bulk fetch opportunity35 # A local resource registry that only contains resources defined36 # in the transitive dependency tree of the loaded profile.37 @resource_registry = Inspec::Resource.new_registry38 @library_eval_context = Inspec::LibraryEvalContext.create(@resource_registry, @require_loader)39 @current_load = nil40 end41 def attributes42 Inspec::AttributeRegistry.list_attributes_for_profile(@profile_id)43 end44 def dependencies45 if @conf['profile'].nil?46 {}47 else48 @conf['profile'].locked_dependencies49 end50 end51 def to_resources_dsl52 Inspec::Resource.create_dsl(self)53 end54 def control_eval_context55 @control_eval_context ||= begin56 ctx = Inspec::ControlEvalContext.create(self, to_resources_dsl)57 ctx.new(@backend, @conf, dependencies, @require_loader, @skip_only_if_eval)58 end59 end60 def reload_dsl61 @control_eval_context = nil62 end63 def profile_supports_platform?64 return true if @conf['profile'].nil?65 @conf['profile'].supports_platform?66 end67 def profile_supports_inspec_version?68 return true if @conf['profile'].nil?69 @conf['profile'].supports_runtime?70 end71 def remove_rule(id)72 @rules[id] = nil if @rules.key?(id)73 @control_subcontexts.each do |c|74 c.remove_rule(id)75 end76 end77 def all_controls78 ret = @rules.values79 ret += @control_subcontexts.map(&:all_rules).flatten80 ret81 end82 alias all_rules all_controls83 def subcontext_by_name(name)84 found = @lib_subcontexts.find { |c| c.profile_id == name }85 if !found86 @lib_subcontexts.each do |c|87 found = c.subcontext_by_name(name)88 break if found89 end90 end91 found92 end93 def add_resources(context)94 @resource_registry.merge!(context.resource_registry)95 control_eval_context.add_resources(context)96 @lib_subcontexts << context97 reload_dsl98 end99 def add_subcontext(context)100 @control_subcontexts << context101 end102 def load_libraries(libs)103 lib_prefix = 'libraries' + File::SEPARATOR104 autoloads = []105 libs.sort_by! { |l| l[1] } # Sort on source path so load order is deterministic106 libs.each do |content, source, line|107 path = source108 if source.start_with?(lib_prefix)109 path = source.sub(lib_prefix, '')110 autoloads.push(path) if File.dirname(path) == '.'111 end112 @require_loader.add(path, content, source, line)113 end114 # load all files directly that are flat inside the libraries folder115 autoloads.each do |path|116 next unless path.end_with?('.rb')117 load_library_file(*@require_loader.load(path)) unless @require_loader.loaded?(path)118 end119 reload_dsl120 end121 def load_control_file(*args)122 # Set `skip_file` to `false` between file loads to prevent skips from spanning multiple control files123 control_eval_context.skip_file = false124 load_with_context(control_eval_context, *args)125 end126 alias load load_control_file127 def load_library_file(*args)128 load_with_context(@library_eval_context, *args)129 end130 def load_with_context(context, content, source = nil, line = nil)131 Inspec::Log.debug("Loading #{source || '<anonymous content>'} into #{self}")132 @current_load = { file: source }133 if content.is_a? Proc134 context.instance_eval(&content)135 elsif source.nil? && line.nil?136 context.instance_eval(content)137 else138 context.instance_eval(content, source || 'unknown', line || 1)...

Full Screen

Full Screen

control_eval_context

Using AI Code Generation

copy

Full Screen

1 @control_eval_context ||= Inspec::ControlEvalContext.new(self)2 @control_eval_context ||= Inspec::ControlEvalContext.new(self)3 @control_eval_context ||= Inspec::ControlEvalContext.new(self)4 @control_eval_context ||= Inspec::ControlEvalContext.new(self)5 @control_eval_context ||= Inspec::ControlEvalContext.new(self)6 @control_eval_context ||= Inspec::ControlEvalContext.new(self)

Full Screen

Full Screen

control_eval_context

Using AI Code Generation

copy

Full Screen

1 it { should cmp 'test' }2 it { should cmp 'test' }3 it { should cmp 'test' }4 it { should cmp 'test' }5 it { should cmp 'test' }6 it { should cmp 'test' }7 it { should cmp 'test' }8 it { should cmp 'test' }9 it { should cmp 'test' }

Full Screen

Full Screen

control_eval_context

Using AI Code Generation

copy

Full Screen

1 its('ServerVersion') { should cmp >= '1.12' }2 its('SecurityOptions') { should include 'name=tlsverify' }3 its('ServerVersion') { should cmp >= '1.12' }4 its('SecurityOptions') { should include 'name=tlscacert' }5 its('ServerVersion') { should cmp >= '1.12' }6 its('SecurityOptions') { should include 'name=tlscert' }7 its('ServerVersion') { should cmp >= '1.12' }8 its('SecurityOptions') { should include 'name=tlskey' }9 its('ServerVersion') { should cmp >= '1.12' }10 its('SecurityOptions') { should include 'name=client-cert' }11 its('ServerVersion') { should cmp >= '1.12' }12 its('SecurityOptions') { should include 'name=client-key' }

Full Screen

Full Screen

control_eval_context

Using AI Code Generation

copy

Full Screen

1control_id = control_context.instance_variable_get(:@__control_id)2control_file_name = control_context.instance_variable_get(:@__control_file)3control_file_content = File.read(control_file_name)

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