Class: Puppet::Provider::Openssl

Inherits:
Puppet::Provider
  • Object
show all
Includes:
Util::POSIX
Defined in:
lib/puppet/provider/openssl.rb

Overview

class to use in openssl providers to handle file permission (mode, group and owner)

Instance Method Summary collapse

Instance Method Details

#groupObject



23
24
25
26
27
28
29
# File 'lib/puppet/provider/openssl.rb', line 23

def group
  if File.exist?(@resource[:path])
    Etc.getgrgid(File.stat(@resource[:path]).gid).name
  else
    :absent
  end
end

#group=(should) ⇒ Object



31
32
33
34
35
# File 'lib/puppet/provider/openssl.rb', line 31

def group=(should)
  File.chown(nil, gid(should), resource[:path])
rescue StandardError => e
  raise Puppet::Error, _("Failed to set group to '#{should}': #{e}"), detail.backtrace
end

#modeObject

Return the mode as an octal string, not as an integer.



38
39
40
41
42
43
44
# File 'lib/puppet/provider/openssl.rb', line 38

def mode
  if File.exist?(@resource[:path])
    format('0%o', (File.stat(@resource[:path]).mode & 0o07777))
  else
    :absent
  end
end

#mode=(should) ⇒ Object

Set the file mode, converting from a string to an integer.



47
48
49
# File 'lib/puppet/provider/openssl.rb', line 47

def mode=(should)
  File.chmod(Integer("0#{should}"), @resource[:path])
end

#ownerObject



9
10
11
12
13
14
15
# File 'lib/puppet/provider/openssl.rb', line 9

def owner
  if File.exist?(@resource[:path])
    Etc.getpwuid(File.stat(@resource[:path]).uid).name
  else
    :absent
  end
end

#owner=(should) ⇒ Object



17
18
19
20
21
# File 'lib/puppet/provider/openssl.rb', line 17

def owner=(should)
  File.chown(uid(should), nil, resource[:path])
rescue StandardError => e
  raise Puppet::Error, _("Failed to set owner to '#{should}': #{e}"), detail.backtrace
end

#set_file_perm(filename, owner = nil, group = nil, mode = nil) ⇒ Object



51
52
53
54
55
# File 'lib/puppet/provider/openssl.rb', line 51

def set_file_perm(filename, owner = nil, group = nil, mode = nil)
  File.chown(uid(owner), nil, resource[:path]) if owner
  File.chown(nil, gid(group), resource[:path]) if group
  File.chmod(Integer("0#{mode}"), filename) if mode
end