Method: Inspec::Profile#initialize

Defined in:
lib/inspec/profile.rb

#initialize(source_reader, options = {}) ⇒ Profile

rubocop:disable Metrics/AbcSize



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
# File 'lib/inspec/profile.rb', line 88

def initialize(source_reader, options = {})
  @source_reader = source_reader
  @target = options[:target]
  @logger = options[:logger] || Logger.new(nil)
  @locked_dependencies = options[:dependencies]
  @controls = options[:controls] || []
  @writable = options[:writable] || false
  @profile_id = options[:id]
  @cache = options[:vendor_cache] || Cache.new
  @attr_values = options[:attributes]
  @tests_collected = false
  @libraries_loaded = false
  @check_mode = options[:check_mode] || false
  Metadata.finalize(@source_reader., @profile_id, options)

  # 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`
  train_options = options.reject { |k, _| k == 'target' } # See https://github.com/chef/inspec/pull/1646
  @backend = options[:backend].nil? ? Inspec::Backend.create(train_options) : options[:backend].dup
  @runtime_profile = RuntimeProfile.new(self)
  @backend.profile = @runtime_profile

  @runner_context =
    options[:profile_context] ||
    Inspec::ProfileContext.for_profile(self, @backend, @attr_values)

  @supports_platform = .supports_platform?(@backend)
  @supports_runtime = .supports_runtime?
end