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
# 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)

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

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

Instance Method Details

#local?Boolean



33
34
35
# File 'lib/train-puppetdb/connection.rb', line 33

def local?
  false
end

#puppetdb_clientObject



41
42
43
# File 'lib/train-puppetdb/connection.rb', line 41

def puppetdb_client
  @client
end

#uriObject



37
38
39
# File 'lib/train-puppetdb/connection.rb', line 37

def uri
  'puppetdb://'
end