module Puppet::X509::PemStore

Methods for managing PEM encoded files. While PEM encoded strings are always ASCII, the files may contain user specified comments, so they are UTF-8 encoded.

@api private

Public Instance Methods

delete_pem(path) click to toggle source

Delete a pem encoded object, if it exists.

@param path [String] The file path to delete @return [Boolean] Returns true if the file was deleted, false otherwise @raise [Errno::EACCES] if permission is denied @api private

   # File lib/puppet/x509/pem_store.rb
50 def delete_pem(path)
51   Puppet::FileSystem.unlink(path)
52   true
53 rescue Errno::ENOENT
54   false
55 end
load_pem(path) click to toggle source

Load a pem encoded object.

@param path [String] file path @return [String, nil] The PEM encoded object or nil if the

path does not exist

@raise [Errno::EACCES] if permission is denied @api private

   # File lib/puppet/x509/pem_store.rb
17 def load_pem(path)
18   Puppet::FileSystem.read(path, encoding: 'UTF-8')
19 rescue Errno::ENOENT
20   nil
21 end
save_pem(pem, path, owner: nil, group: nil, mode: 0644) click to toggle source

Save pem encoded content to a file. If the file doesn't exist, it will be created. Otherwise, the file will be overwritten. In both cases the contents will be overwritten atomically so other processes don't see a partially written file.

@param pem [String] The PEM encoded object to write @param path [String] The file path to write to @raise [Errno::EACCES] if permission is denied @raise [Errno::EPERM] if the operation cannot be completed @api private

   # File lib/puppet/x509/pem_store.rb
33 def save_pem(pem, path, owner: nil, group: nil, mode: 0644)
34   Puppet::FileSystem.replace_file(path, mode) do |f|
35     f.set_encoding('UTF-8')
36     f.write(pem.encode('UTF-8'))
37   end
38 
39   if !Puppet::Util::Platform.windows? && Puppet.features.root? && (owner || group)
40     FileUtils.chown(owner, group, path)
41   end
42 end