Method: Inspec::Profile#initialize
- Defined in:
- lib/inspec/profile.rb
#initialize(source_reader, options = {}) ⇒ Profile
rubocop:disable Metrics/AbcSize
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/inspec/profile.rb', line 83 def initialize(source_reader, = {}) @source_reader = source_reader @target = [:target] @logger = [:logger] || Logger.new(nil) @locked_dependencies = [:dependencies] @controls = [:controls] || [] @writable = [:writable] || false @profile_id = [:id] @profile_name = [:profile_name] @cache = [:vendor_cache] || Cache.new @input_values = [:inputs] @tests_collected = false @libraries_loaded = false @check_mode = [:check_mode] || false @parent_profile = [:parent_profile] @legacy_profile_path = [:profiles_path] || false Metadata.finalize(@source_reader., @profile_id, ) # if a backend has already been created, clone it so each profile has its own unique backend object # otherwise, create a new backend object # # This is necessary since we store the RuntimeProfile on the backend object. If a user runs `inspec exec` # with multiple profiles, only the RuntimeProfile for the last-loaded profile will be available if # we share the backend between profiles. # # This will cause issues if a profile attempts to load a file via `inspec.profile.file` = .reject { |k, _| k == "target" } # See https://github.com/chef/inspec/pull/1646 @backend = [:backend].nil? ? Inspec::Backend.create(Inspec::Config.new()) : [:backend].dup @runtime_profile = RuntimeProfile.new(self) @backend.profile = @runtime_profile # The AttributeRegistry is in charge of keeping track of inputs; # it is the single source of truth. Now that we have a profile object, # we can create any inputs that were provided by various mechanisms. [:runner_conf] ||= Inspec::Config.cached # Catch legacy CLI input option usage if [:runner_conf].key?(:attrs) Inspec.deprecate(:rename_attributes_to_inputs, "Use --input-file on the command line instead of --attrs.") [:runner_conf][:input_file] = [:runner_conf].delete(:attrs) elsif [:runner_conf].key?(:input_files) # The kitchen-inspec docs say to use plural. Our CLI and internal expectations are singular. [:runner_conf][:input_file] = [:runner_conf].delete(:input_files) end # Catch legacy kitchen-inspec input usage if [:runner_conf].key?(:attributes) Inspec.deprecate(:rename_attributes_to_inputs, "Use :inputs in your kitchen.yml verifier config instead of :attributes.") [:runner_conf][:inputs] = [:runner_conf].delete(:attributes) end Inspec::InputRegistry.bind_profile_inputs( # Every input only exists in the context of a profile .params[:name], # TODO: test this with profile aliasing # Remaining args are possible sources of inputs cli_input_files: [:runner_conf][:input_file], # From CLI --input-file profile_metadata: , runner_api: [:runner_conf][:inputs], # This is the route the audit_cookbook and kitchen-inspec take cli_input_arg: [:runner_conf][:input] # The --input name=value CLI option ) @runner_context = [:profile_context] || Inspec::ProfileContext.for_profile(self, @backend) @supports_platform = .supports_platform?(@backend) @supports_runtime = .supports_runtime? end |