Skip to content

Commit

Permalink
Merge pull request #73 from h0tw1r3/puppetdb_token_auth
Browse files Browse the repository at this point in the history
support puppetdb token authentication
  • Loading branch information
ekohl authored Jan 12, 2024
2 parents 09200d0 + e7757b3 commit ad5edd4
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 ad5edd4

Please sign in to comment.