Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support puppetdb token authentication #73

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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