Class: OodSupport::ACLs::Nfs4ACL

Inherits:
OodSupport::ACL show all
Defined in:
lib/ood_support/acls/nfs4.rb

Overview

Object describing an NFSv4 ACL

Constant Summary collapse

GET_FACL_BIN =

The binary used to get the file ACLs

'nfs4_getfacl'
SET_FACL_BIN =

The binary used to set the file ACLs

'nfs4_setfacl'

Instance Attribute Summary collapse

Attributes inherited from OodSupport::ACL

#default, #entries

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from OodSupport::ACL

#==, #eql?, #hash, parse, #to_s

Constructor Details

#initialize(owner:, group:, **kwargs) ⇒ Nfs4ACL

Returns a new instance of Nfs4ACL.

Parameters:

  • owner (#to_s)

    name of owner

  • group (#to_s)

    name of group

See Also:



95
96
97
98
99
# 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

Instance Attribute Details

#groupString (readonly)

Name of owning group for this ACL

Returns:

  • (String)

    group name



19
20
21
# File 'lib/ood_support/acls/nfs4.rb', line 19

def group
  @group
end

#ownerString (readonly)

Name of owner for this ACL

Returns:

  • (String)

    owner name



15
16
17
# File 'lib/ood_support/acls/nfs4.rb', line 15

def owner
  @owner
end

Class Method Details

.add_facl(path:, entry:) ⇒ Nfs4ACL

Add ACL to file path

Parameters:

  • path (String)

    path to file or directory

  • entry (Nfs4Entry)

    entry to add to file

Returns:

Raises:

  • (InvalidPath)

    file path doesn’t exist

  • (BadExitCode)

    the command line called exited with non-zero status



41
42
43
44
45
46
47
# 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:) ⇒ Nfs4ACL

Get ACL from file path

Parameters:

  • path (String)

    path to file or directory

Returns:

  • (Nfs4ACL)

    acl generated from path

Raises:

  • (InvalidPath)

    file path doesn’t exist

  • (BadExitCode)

    the command line called exited with non-zero status



26
27
28
29
30
31
32
33
# 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:) ⇒ Nfs4ACL

Modify in-place an entry for file path

Parameters:

  • path (String)

    path to file or directory

  • old_entry (Nfs4Entry)

    old entry to modify in-place in file

  • new_entry (Nfs4Entry)

    new entry to be replaced with

Returns:

Raises:

  • (InvalidPath)

    file path doesn’t exist

  • (BadExitCode)

    the command line called exited with non-zero status



70
71
72
73
74
75
76
# 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

.rem_facl(path:, entry:) ⇒ Nfs4ACL

Remove ACL from file path

Parameters:

  • path (String)

    path to file or directory

  • entry (Nfs4Entry)

    entry to remove from file

Returns:

Raises:

  • (InvalidPath)

    file path doesn’t exist

  • (BadExitCode)

    the command line called exited with non-zero status



55
56
57
58
59
60
61
# 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:) ⇒ Nfs4ACL

Set ACL (overwrites original) for file path

Parameters:

  • path (String)

    path to file or directory

  • acl (Nfs4ACL)

    ACL to overwrite original with

Returns:

Raises:

  • (InvalidPath)

    file path doesn’t exist

  • (BadExitCode)

    the command line called exited with non-zero status



84
85
86
87
88
89
90
# 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

Instance Method Details

#allow?(principle:, permission:) ⇒ Boolean

Check if queried principle has access to resource

Parameters:

  • principle (User, Group)

    principle to check against

  • permission (Symbol)

    permission to check against

Returns:

  • (Boolean)

    does principle have access?



105
106
107
108
# 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_hHash

Convert object to hash

Returns:

  • (Hash)

    the hash describing this object



112
113
114
# File 'lib/ood_support/acls/nfs4.rb', line 112

def to_h
  super.merge owner: owner, group: group
end