Module: Inspec::Backend

Defined in:
lib/inspec/backend.rb

Defined Under Namespace

Modules: Base

Class Method Summary collapse

Class Method Details

.create(config) ⇒ TransportBackend

Create the transport backend with aggregated resources.

Parameters:

  • config (Hash)

    for the transport backend

Returns:

  • (TransportBackend)

    enriched transport instance



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/inspec/backend.rb', line 35

def self.create(config)
  conf = Train.target_config(config)
  name = Train.validate_backend(conf)
  transport = Train.create(name, conf)
  if transport.nil?
    raise "Can't find transport backend '#{name}'."
  end

  connection = transport.connection
  if connection.nil?
    raise "Can't connect to transport backend '#{name}'."
  end

  cls = Class.new do
    include Base

    define_method :backend do
      connection
    end

    Inspec::Resource.registry.each do |id, r|
      define_method id.to_sym do |*args|
        r.new(self, id.to_s, *args)
      end
    end
  end

  cls.new

rescue Train::ClientError => e
  raise "Client error, can't connect to '#{name}' backend: #{e.message}"
rescue Train::TransportError => e
  raise "Transport error, can't connect to '#{name}' backend: #{e.message}"
end