Class: PuppetGhostbuster::PuppetDB

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet-ghostbuster/puppetdb.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.classesObject



41
42
43
44
45
46
# File 'lib/puppet-ghostbuster/puppetdb.rb', line 41

def self.classes
  @@classes ||= client.request('',
                               'resources[title] { type = "Class" and nodes { deactivated is null } group by title }').data.map do |r|
    r['title']
  end
end

.clientObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/puppet-ghostbuster/puppetdb.rb', line 15

def self.client
  @@client ||= begin
    options = {
      server: ENV['PUPPETDB_URL'] || @@puppetdb,
    }

    if ENV['PE_TOKEN']
      token_file = File.expand_path(ENV['PE_TOKEN'])
      options[:token] = File.exist?(token_file) ? File.read(token_file) : ENV.fetch('PE_TOKEN')
      options[:cacert] = ENV['PUPPETDB_CACERT_FILE'] || Puppet[:localcacert]
    else
      options[:pem] = {
        'key' => ENV['PUPPETDB_KEY_FILE'] || Puppet[:hostprivkey],
        'cert' => ENV['PUPPETDB_CERT_FILE'] || Puppet[:hostcert],
        'ca_file' => ENV['PUPPETDB_CACERT_FILE'] || Puppet[:localcacert],
      }
    end

    ::PuppetDB::Client.new(options, 4)
  end
end

.resourcesObject



52
53
54
55
56
# File 'lib/puppet-ghostbuster/puppetdb.rb', line 52

def self.resources
  @@resources ||= client.request('', 'resources[type] { nodes { deactivated is null } group by type }').data.map do |r|
    r['type']
  end
end

Instance Method Details

#classesObject



48
49
50
# File 'lib/puppet-ghostbuster/puppetdb.rb', line 48

def classes
  self.class.classes
end

#clientObject



37
38
39
# File 'lib/puppet-ghostbuster/puppetdb.rb', line 37

def client
  self.class.client
end

#resourcesObject



58
59
60
# File 'lib/puppet-ghostbuster/puppetdb.rb', line 58

def resources
  self.class.resources
end