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.

Parameters:

  • path (String)

    The file path to delete

Returns:

  • (Boolean)

    Returns true if the file was deleted, false otherwise

Raises:

  • (Errno::EACCES)

    if permission is denied



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

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.

Parameters:

  • path (String)

    file path

Returns:

  • (String, nil)

    The PEM encoded object or nil if the path does not exist

Raises:

  • (Errno::EACCES)

    if permission is denied



18
19
20
21
22
# File 'lib/puppet/x509/pem_store.rb', line 18

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: 0o644) ⇒ 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.

Parameters:

  • pem (String)

    The PEM encoded object to write

  • path (String)

    The file path to write to

Raises:

  • (Errno::EACCES)

    if permission is denied

  • (Errno::EPERM)

    if the operation cannot be completed



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

def save_pem(pem, path, owner: nil, group: nil, mode: 0o644)
  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