Skip to content
Open
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: 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('.')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't it be easier to always use the networking.fqdn fact? I think when there's no domain, facter will set the fqdn to the hostname?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems reasonable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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