Skip to content

Commit

Permalink
Face: do not rely on legacy facts
Browse files Browse the repository at this point in the history
  • Loading branch information
bastelfreak committed Jun 25, 2024
1 parent 382cf18 commit 1a3924e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
5 changes: 3 additions & 2 deletions lib/puppetserver/ca/config/puppet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ def load(cli_overrides: {}, logger:, ca_dir_warn: true)
end

def default_certname
hostname = Facter.value(:hostname)
domain = Facter.value(:domain)
networking = Facter.value(:networking)
hostname = networking[:hostname]
domain = networking[:domain]
if domain and domain != ''
fqdn = [hostname, domain].join('.')
else
Expand Down
6 changes: 2 additions & 4 deletions spec/puppetserver/ca/config/puppet_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -338,16 +338,14 @@

context 'building the default certname' do
it 'when there is a domain, concatenates the hostname and domain' do
expect(Facter).to receive(:value).with(:hostname).and_return("foo")
expect(Facter).to receive(:value).with(:domain).and_return("example.com")
expect(Facter).to receive(:value).with(:networking).and_return({domain: 'example.com', hostname: 'foo'})

conf = Puppetserver::Ca::Config::Puppet.new
expect(conf.default_certname).to eq("foo.example.com")
end

it 'when domain is nil, returns just the hostname' do
expect(Facter).to receive(:value).with(:hostname).and_return("foo")
expect(Facter).to receive(:value).with(:domain).and_return(nil)
expect(Facter).to receive(:value).with(:networking).and_return({domain: nil, hostname: 'foo'})

conf = Puppetserver::Ca::Config::Puppet.new
expect(conf.default_certname).to eq("foo")
Expand Down

0 comments on commit 1a3924e

Please sign in to comment.