Class: TrainPlugins::PuppetDBInterface::Connection

Inherits:
Train::Plugins::Transport::BaseConnection
  • Object
show all
Includes:
Platform
Defined in:
lib/train-puppetdb/connection.rb

Instance Method Summary collapse

Methods included from Platform

#platform

Constructor Details

#initialize(options) ⇒ Connection



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/train-puppetdb/connection.rb', line 9

def initialize(options)
  if options.nil? || options[:server].nil?
    raise Train::TransportError, "You must set a PuppetDB server."
  end

  super(options)

  @tmp_dir = Dir.mktmpdir

  # Check if target is reachable
  begin
    @client = PuppetDB::Client.new({
      :server => options[:server],
      :pem => {
        'key' => sanitize_cert("key", options[:key]),
        'cert' => sanitize_cert("cert", options[:cert]),
        'ca_file' => sanitize_cert("ca", options[:cacert]),
      }
    })

    @client.request('nodes', [:'~', 'certname', '.*'], {:limit => 1})
  rescue => e
    raise Train::TransportError, e.response
  end
end

Instance Method Details

#local?Boolean



35
36
37
# File 'lib/train-puppetdb/connection.rb', line 35

def local?
  false
end

#puppetdb_clientObject



43
44
45
# File 'lib/train-puppetdb/connection.rb', line 43

def puppetdb_client
  @client
end

#uriObject



39
40
41
# File 'lib/train-puppetdb/connection.rb', line 39

def uri
  'puppetdb://'
end