class OodSupport::ACLs::Nfs4ACL

Object describing an NFSv4 ACL

Constants

GET_FACL_BIN

The binary used to get the file ACLs

SET_FACL_BIN

The binary used to set the file ACLs

Attributes

group[R]

Name of owning group for this ACL @return [String] group name

owner[R]

Name of owner for this ACL @return [String] owner name

Public Class Methods

add_facl(path:, entry:) click to toggle source

Add ACL to file path @param path [String] path to file or directory @param entry [Nfs4Entry] entry to add to file @raise [InvalidPath] file path doesn't exist @raise [BadExitCode] the command line called exited with non-zero status @return [Nfs4ACL] new acl of path

# File lib/ood_support/acls/nfs4.rb, line 41
def self.add_facl(path:, entry:)
  path = Pathname.new path
  raise InvalidPath, "invalid path: #{path}" unless path.exist?
  _, err, s = Open3.capture3(SET_FACL_BIN, '-a', entry.to_s, path.to_s)
  raise BadExitCode, err unless s.success?
  get_facl(path: path)
end
get_facl(path:) click to toggle source

Get ACL from file path @param path [String] path to file or directory @raise [InvalidPath] file path doesn't exist @raise [BadExitCode] the command line called exited with non-zero status @return [Nfs4ACL] acl generated from path

# File lib/ood_support/acls/nfs4.rb, line 26
def self.get_facl(path:)
  path = Pathname.new path
  raise InvalidPath, "invalid path: #{path}" unless path.exist?
  stat = path.stat
  acl, err, s = Open3.capture3(GET_FACL_BIN, path.to_s)
  raise BadExitCode, err unless s.success?
  parse(acl, owner: User.new(stat.uid), group: Group.new(stat.gid))
end
mod_facl(path:, old_entry:, new_entry:) click to toggle source

Modify in-place an entry for file path @param path [String] path to file or directory @param old_entry [Nfs4Entry] old entry to modify in-place in file @param new_entry [Nfs4Entry] new entry to be replaced with @raise [InvalidPath] file path doesn't exist @raise [BadExitCode] the command line called exited with non-zero status @return [Nfs4ACL] new acl of path

# File lib/ood_support/acls/nfs4.rb, line 70
def self.mod_facl(path:, old_entry:, new_entry:)
  path = Pathname.new path
  raise InvalidPath, "invalid path: #{path}" unless path.exist?
  _, err, s = Open3.capture3(SET_FACL_BIN, '-m', old_entry.to_s, new_entry.to_s, path.to_s)
  raise BadExitCode, err unless s.success?
  get_facl(path: path)
end
new(owner:, group:, **kwargs) click to toggle source

@param owner [#to_s] name of owner @param group [#to_s] name of group @see ACL#initialize

Calls superclass method OodSupport::ACL::new
# File lib/ood_support/acls/nfs4.rb, line 95
def initialize(owner:, group:, **kwargs)
  super(kwargs.merge(default: false))
  @owner = owner.to_s
  @group = group.to_s
end
rem_facl(path:, entry:) click to toggle source

Remove ACL from file path @param path [String] path to file or directory @param entry [Nfs4Entry] entry to remove from file @raise [InvalidPath] file path doesn't exist @raise [BadExitCode] the command line called exited with non-zero status @return [Nfs4ACL] new acl of path

# File lib/ood_support/acls/nfs4.rb, line 55
def self.rem_facl(path:, entry:)
  path = Pathname.new path
  raise InvalidPath, "invalid path: #{path}" unless path.exist?
  _, err, s = Open3.capture3(SET_FACL_BIN, '-x', entry.to_s, path.to_s)
  raise BadExitCode, err unless s.success?
  get_facl(path: path)
end
set_facl(path:, acl:) click to toggle source

Set ACL (overwrites original) for file path @param path [String] path to file or directory @param acl [Nfs4ACL] ACL to overwrite original with @raise [InvalidPath] file path doesn't exist @raise [BadExitCode] the command line called exited with non-zero status @return [Nfs4ACL] new acl of path

# File lib/ood_support/acls/nfs4.rb, line 84
def self.set_facl(path:, acl:)
  path = Pathname.new path
  raise InvalidPath, "invalid path: #{path}" unless path.exist?
  _, err, s = Open3.capture3(SET_FACL_BIN, '-s', acl.to_s, path.to_s)
  raise BadExitCode, err unless s.success?
  get_facl(path: path)
end

Private Class Methods

entry_class() click to toggle source

Use Nfs4Entry for entry objects

# File lib/ood_support/acls/nfs4.rb, line 118
def self.entry_class
  Nfs4Entry
end

Public Instance Methods

allow?(principle:, permission:) click to toggle source

Check if queried principle has access to resource @param principle [User, Group] principle to check against @param permission [Symbol] permission to check against @return [Boolean] does principle have access?

# File lib/ood_support/acls/nfs4.rb, line 105
def allow?(principle:, permission:)
  # Check in array order
  ordered_check(principle: principle, permission: permission, owner: owner, group: group)
end
to_h() click to toggle source

Convert object to hash @return [Hash] the hash describing this object

Calls superclass method OodSupport::ACL#to_h
# File lib/ood_support/acls/nfs4.rb, line 112
def to_h
  super.merge owner: owner, group: group
end