Skip to content

Commit

Permalink
support puppetdb token authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
h0tw1r3 committed Jan 10, 2024
1 parent 1cc428a commit e7757b3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ An SSL certificate signed by your site’s Puppet CA

The private key for that certificate

### PE_TOKEN

If set, PE token authentication will be used instead of certificate authentication.
Value may be a token _or_ path to a file containing a token.

Plugins
-------

Expand Down
27 changes: 19 additions & 8 deletions lib/puppet-ghostbuster/puppetdb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,25 @@ class PuppetDB
end

def self.client
@@client ||= ::PuppetDB::Client.new({
server: ENV['PUPPETDB_URL'] || @@puppetdb,
pem: {
'key' => ENV['PUPPETDB_KEY_FILE'] || Puppet[:hostprivkey],
'cert' => ENV['PUPPETDB_CERT_FILE'] || Puppet[:hostcert],
'ca_file' => ENV['PUPPETDB_CACERT_FILE'] || Puppet[:localcacert],
},
}, 4)
@@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

def client
Expand Down

0 comments on commit e7757b3

Please sign in to comment.