Module: Puppet::X509::PemStore Private

Included in:
CertProvider
Defined in:
lib/puppet/x509/pem_store.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

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.

Instance Method Summary collapse

Instance Method Details

#delete_pem(path) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Delete a pem encoded object, if it exists.

Raises:

  • (Errno::EACCES)

    if permission is denied


49
50
51
52
53
54
# File 'lib/puppet/x509/pem_store.rb', line 49

def delete_pem(path)
  Puppet::FileSystem.unlink(path)
  true
rescue Errno::ENOENT
  false
end

#load_pem(path) ⇒ String?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Load a pem encoded object.

Raises:

  • (Errno::EACCES)

    if permission is denied


16
17
18
19
20
# File 'lib/puppet/x509/pem_store.rb', line 16

def load_pem(path)
  Puppet::FileSystem.read(path, encoding: 'UTF-8')
rescue Errno::ENOENT
  nil
end

#save_pem(pem, path, owner: nil, group: nil, mode: 0644) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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.

Raises:

  • (Errno::EACCES)

    if permission is denied

  • (Errno::EPERM)

    if the operation cannot be completed


32
33
34
35
36
37
38
39
40
41
# File 'lib/puppet/x509/pem_store.rb', line 32

def save_pem(pem, path, owner: nil, group: nil, mode: 0644)
  Puppet::FileSystem.replace_file(path, mode) do |f|
    f.set_encoding('UTF-8')
    f.write(pem.encode('UTF-8'))
  end

  if !Puppet::Util::Platform.windows? && Puppet.features.root? && (owner || group)
    FileUtils.chown(owner, group, path)
  end
end