Skip to content

Commit f843c1f

Browse files
committed
(PUP-10639) Add methods for getting/setting CA last update time
This is similar to the getter/setter methods for the CRL, using the CA file's mtime to determine the last time it was updated.
1 parent 9f08d1e commit f843c1f

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

lib/puppet/x509/cert_provider.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,28 @@ def crl_last_update=(time)
147147
Puppet::FileSystem.touch(@crlpath, mtime: time)
148148
end
149149

150+
# Return the time when the CA bundle was last updated.
151+
#
152+
# @return [Time, nil] Time when the CA bundle was last updated, or nil if we don't
153+
# have a CA bundle
154+
#
155+
# @api private
156+
def ca_last_update
157+
stat = Puppet::FileSystem.stat(@capath)
158+
Time.at(stat.mtime)
159+
rescue Errno::ENOENT
160+
nil
161+
end
162+
163+
# Set the CA bundle last updated time.
164+
#
165+
# @param time [Time] The last updated time
166+
#
167+
# @api private
168+
def ca_last_update=(time)
169+
Puppet::FileSystem.touch(@capath, mtime: time)
170+
end
171+
150172
# Save named private key in the configured `privatekeydir`. For
151173
# historical reasons, names are case insensitive.
152174
#

spec/unit/x509/cert_provider_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,32 @@ def expects_private_file(path)
586586
end
587587
end
588588

589+
context 'CA last update time' do
590+
let(:ca_path) { tmpfile('pem_ca') }
591+
592+
it 'returns nil if the CA does not exist' do
593+
provider = create_provider(capath: '/does/not/exist')
594+
595+
expect(provider.ca_last_update).to be_nil
596+
end
597+
598+
it 'returns the last update time' do
599+
time = Time.now - 30
600+
Puppet::FileSystem.touch(ca_path, mtime: time)
601+
provider = create_provider(capath: ca_path)
602+
603+
expect(provider.ca_last_update).to be_within(1).of(time)
604+
end
605+
606+
it 'sets the last update time' do
607+
time = Time.now - 30
608+
provider = create_provider(capath: ca_path)
609+
provider.ca_last_update = time
610+
611+
expect(Puppet::FileSystem.stat(ca_path).mtime).to be_within(1).of(time)
612+
end
613+
end
614+
589615
context 'CRL last update time' do
590616
let(:crl_path) { tmpfile('pem_crls') }
591617

0 commit comments

Comments
 (0)