module Inspec

copyright: 2017, Chef Software Inc.

For backwards compatibility during the rename (see #3802), maintain the Inspec::Attribute namespace for people checking for Inspec::Attribute::DEFAULT_ATTRIBUTE

copyright: 2015, Vulcano Security GmbH

Any additions to RSpec::Core::ExampleGroup (the RSpec class behind describe blocks) should go here.

spec requirements

There be dragons!! Or borgs, or something… This file and all its contents cannot be unit-tested. both test-suites collide and disable all unit tests that have been added.

Copyright 2017 Chef Software

These type occur only when running “inspec exec –reporter json <file>”.

These type occur only when running “exec –reporter json-min <file>”.

These elements are shared between more than one output type

These type occur only when running “inspec json <file>”.

Constants

RunData
SecretsBackend
SourceReader
VERSION

Public Class Methods

config_dir() click to toggle source
# File lib/inspec/globals.rb, line 6
def self.config_dir
  ENV["INSPEC_CONFIG_DIR"] || File.join(home_path, ".inspec")
end
deprecate(group, msg = "", opts = {}) click to toggle source
# File lib/inspec/utils/deprecation/global_method.rb, line 4
def self.deprecate(group, msg = "", opts = {})
  config_io = opts.delete(:config_io)
  deprecator = Inspec::Deprecation::Deprecator.new(config_io: config_io)
  deprecator.handle_deprecation(group, msg, opts)
end
fetcher(version) click to toggle source
# File lib/inspec/fetcher.rb, line 33
def self.fetcher(version)
  if version != 1
    raise "Only fetcher version 1 is supported!"
  end

  Inspec::Plugins::Fetcher
end
home_path() click to toggle source
# File lib/inspec/globals.rb, line 14
def self.home_path
  Dir.home
rescue ArgumentError, NoMethodError
  # If ENV['HOME'] is not set, Dir.home will fail due to expanding the ~. Fallback to Etc.
  require "etc" unless defined?(Etc)
  Etc.getpwuid.dir
end
plugin(version, plugin_type = nil) click to toggle source

Provides the base class that plugin implementors should use.

# File lib/inspec/plugin/v2.rb, line 42
def self.plugin(version, plugin_type = nil)
  unless version == 2
    raise "Only plugins version 2 is supported!"
  end

  return Inspec::Plugin::V2::PluginBase if plugin_type.nil?

  Inspec::Plugin::V2::PluginBase.base_class_for_type(plugin_type)
end
record_telemetry_data(data_series_name, data_point = nil) { || ... } click to toggle source

A Global method to add a data series object to the Telemetry Collection. `data_series_name`s are unique, so `:dependency_group` will always return the same object. `data_point` is optional, you may also supply a block with several data points. All data points should allow to_s

# File lib/inspec/utils/telemetry/global_methods.rb, line 9
def self.record_telemetry_data(data_series_name, data_point = nil)
  coll = Inspec::Telemetry::Collector.instance
  return unless coll.telemetry_enabled?

  ds = coll.find_or_create_data_series(data_series_name)
  return unless ds.enabled?

  if block_given?
    ds << yield
  else
    ds << data_point
  end
end
resource(version) click to toggle source

Retrieve the base class for creating a new resource. Create classes that inherit from this class.

@param [int] version the resource version to use @return [Resource] base class for creating a new resource

# File lib/inspec/resource.rb, line 243
def self.resource(version)
  validate_resource_dsl_version!(version)
  Inspec::Resource
end
secrets(version) click to toggle source
# File lib/inspec/secrets.rb, line 6
def self.secrets(version)
  if version != 1
    raise "Only secrets version 1 is supported!"
  end

  Inspec::Plugins::Secret
end
source_reader(version) click to toggle source
# File lib/inspec/source_reader.rb, line 16
def self.source_reader(version)
  if version != 1
    raise "Only source readers version 1 is supported!"
  end

  Inspec::Plugins::SourceReader
end
src_root() click to toggle source
# File lib/inspec/globals.rb, line 10
def self.src_root
  @src_root ||= File.expand_path(File.join(__FILE__, "../../.."))
end
validate_resource_dsl_version!(version) click to toggle source
# File lib/inspec/resource.rb, line 248
def self.validate_resource_dsl_version!(version)
  raise "Only resource version 1 is supported!" if version != 1
end