Class: TrainPlugins::PuppetDBInterface::Connection
- Inherits:
-
Train::Plugins::Transport::BaseConnection
- Object
- Train::Plugins::Transport::BaseConnection
- TrainPlugins::PuppetDBInterface::Connection
- Includes:
- Platform
- Defined in:
- lib/train-puppetdb/connection.rb
Instance Method Summary collapse
-
#initialize(options) ⇒ Connection
constructor
A new instance of Connection.
- #local? ⇒ Boolean
- #puppetdb_client ⇒ Object
- #uri ⇒ Object
Methods included from Platform
Constructor Details
#initialize(options) ⇒ Connection
Returns a new instance of 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 34 35 36 37 38 39 40 41 |
# File 'lib/train-puppetdb/connection.rb', line 9 def initialize() if .nil? || [:server].nil? raise Train::TransportError, "You must set a PuppetDB server." end super() if [:cert].start_with?("-----") end begin cert = OpenSSL::X509::Certificate.new(File.read([:cert])) rescue end # Check if target is reachable begin @client = PuppetDB::Client.new({ :server => [:server], :pem => { 'key' => sanitize_cert([:key]), 'cert' => sanitize_cert([:cert]), 'ca_file' => sanitize_cert([:cacert]), } }) @client.request('nodes', [:'~', 'certname', '.*'], {:limit => 1}) rescue => e raise Train::TransportError, e.response end end |
Instance Method Details
#local? ⇒ Boolean
43 44 45 |
# File 'lib/train-puppetdb/connection.rb', line 43 def local? false end |
#puppetdb_client ⇒ Object
51 52 53 |
# File 'lib/train-puppetdb/connection.rb', line 51 def puppetdb_client @client end |
#uri ⇒ Object
47 48 49 |
# File 'lib/train-puppetdb/connection.rb', line 47 def uri 'puppetdb://' end |