Skip to content

Commit 471e39e

Browse files
Merge pull request #8560 from Magisus/backport-default-ca-dr
(PUP-11004) Return new CA location as default if it exists
2 parents 42cb3a3 + cb2ae11 commit 471e39e

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

lib/puppet/defaults.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ def self.default_vendormoduledir
5858
end
5959
end
6060

61+
def self.default_cadir
62+
return "" if Puppet::Util::Platform.windows?
63+
old_ca_dir = "#{Puppet[:ssldir]}/ca"
64+
new_ca_dir = '/etc/puppetlabs/puppetserver/ca'
65+
66+
if File.exist?("#{new_ca_dir}/ca_crt.pem")
67+
new_ca_dir
68+
else
69+
old_ca_dir
70+
end
71+
end
72+
6173
############################################################################################
6274
# NOTE: For information about the available values for the ":type" property of settings,
6375
# see the docs for Settings.define_settings
@@ -1150,7 +1162,7 @@ def self.initialize_default_settings!(settings)
11501162
:desc => "The name to use the Certificate Authority certificate.",
11511163
},
11521164
:cadir => {
1153-
:default => "$ssldir/ca",
1165+
:default => lambda { default_cadir },
11541166
:type => :directory,
11551167
:desc => "The root directory for the certificate authority.",
11561168
},

spec/unit/defaults_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,4 +234,20 @@
234234
Puppet.initialize_settings
235235
end
236236
end
237+
238+
describe "the default cadir", :unless => Puppet::Util::Platform.windows? do
239+
it 'defaults to inside the ssldir if not migrated' do
240+
expect(File).to receive(:exist?).with('/etc/puppetlabs/puppetserver/ca/ca_crt.pem').and_return(false)
241+
expect(Puppet.default_cadir).to eq("#{Puppet[:ssldir]}/ca")
242+
end
243+
244+
it 'returns the new location if there is CA content there' do
245+
expect(File).to receive(:exist?).with('/etc/puppetlabs/puppetserver/ca/ca_crt.pem').and_return(true)
246+
expect(Puppet.default_cadir).to eq('/etc/puppetlabs/puppetserver/ca')
247+
end
248+
249+
it 'returns an empty string for Windows platforms', :if => Puppet::Util::Platform.windows? do
250+
expect(Puppet.default_cadir).to eq("")
251+
end
252+
end
237253
end

0 commit comments

Comments
 (0)