class OodSupport::ACLs::PosixEntry

Object describing single Posix ACL entry

Constants

REGEX_PATTERN

Regular expression used when parsing ACL entry string

VALID_FLAG

Valid flags for an ACL entry

VALID_PERMISSION

Valid permissions for an ACL entry

Attributes

default[R]

Is this a default ACL entry @return [Boolean] whether default acl entry

flag[R]

Flag set on ACL entry @return [Symbol] flag on acl entry

permissions[R]

Permissions of ACL entry @return [Array<Symbol>] permissions of acl entry

Public Class Methods

new(default: false, flag:, permissions:, **kwargs) click to toggle source

@param default [Boolean] whether default acl entry @param flag [#to_sym] flag for entry @param permissions [Array<#to_sym>] list of permissions for entry @see ACLEntry#initialize

Calls superclass method OodSupport::ACLEntry::new
# File lib/ood_support/acls/posix.rb, line 174
def initialize(default: false, flag:, permissions:, **kwargs)
  @default = default
  @flag = flag.to_sym
  @permissions = permissions.map(&:to_sym)
  super(kwargs)
end

Private Class Methods

parse_entry(entry) click to toggle source

Parse an entry string into input parameters

# File lib/ood_support/acls/posix.rb, line 261
def self.parse_entry(entry)
  e = REGEX_PATTERN.match(entry.to_s.strip) do |m|
    {
      default:     m[:default] ? true : false,
      flag:        m[:flag],
      principle:   m[:principle],
      permissions: m[:permissions].chars
    }
  end
  e ? e : raise(InvalidACLEntry, "invalid entry: #{entry}")
end

Public Instance Methods

default_entry?() click to toggle source

Is this a default ACL entry @return [Boolean] is this a default entry

# File lib/ood_support/acls/posix.rb, line 206
def default_entry?
  default
end
group_entry?() click to toggle source

Is this a group-specific ACL entry @return [Boolean] is this a group entry

# File lib/ood_support/acls/posix.rb, line 218
def group_entry?
  !default_entry? && flag == :group
end
group_owner_entry?() click to toggle source

Is this the owning group ACL entry @return [Boolean] is this the owning group entry

# File lib/ood_support/acls/posix.rb, line 236
def group_owner_entry?
  group_entry? && principle.empty?
end
has_permission?(permission:, mask:) click to toggle source

Does this entry have the requested permission @param permission [#to_sym] the requested permission @param mask [PosixEntry] the permissions of the mask entry @return [Boolean] found this permission

# File lib/ood_support/acls/posix.rb, line 244
def has_permission?(permission:, mask:)
  if user_owner_entry? || other_entry?
    permissions.include? permission.to_sym
  else
    (mask ? permissions & mask.permissions : permissions).include? permission.to_sym
  end
end
match(principle:, owner:, group:) click to toggle source

Do the requested args match this ACL entry? @param principle [User, Group, to_s] requested principle @param owner [String] owner of corresponding ACL @param group [String] owning group of corresponding ACL @raise [ArgumentError] principle isn't {User} or {Group} object @return [Boolean] does this match this entry

# File lib/ood_support/acls/posix.rb, line 187
def match(principle:, owner:, group:)
  principle = User.new(principle) if (!principle.is_a?(User) && !principle.is_a?(Group))
  return false if default_entry?
  p = self.principle
  p = owner if user_owner_entry?
  p = group if group_owner_entry?
  if (principle.is_a?(User) && group_entry?)
    principle.groups.include?(p)
  elsif (principle.is_a?(User) && user_entry?) || (principle.is_a?(Group) && group_entry?)
    principle == p
  elsif other_entry?
    true
  else
    false
  end
end
other_entry?() click to toggle source

Is this an other-specific ACL entry @return [Boolean] is this an other entry

# File lib/ood_support/acls/posix.rb, line 224
def other_entry?
  !default_entry? && flag == :other
end
to_s(w_perms: true) click to toggle source

Convert object to string @param w_perms [Boolean] whether display permissions @return [String] the string describing this object

# File lib/ood_support/acls/posix.rb, line 255
def to_s(w_perms: true)
  %[#{"default:" if default_entry?}#{flag}:#{principle}#{":#{permissions.join}" if w_perms}]
end
user_entry?() click to toggle source

Is this a user-specific ACL entry @return [Boolean] is this a user entry

# File lib/ood_support/acls/posix.rb, line 212
def user_entry?
  !default_entry? && flag == :user
end
user_owner_entry?() click to toggle source

Is this the owner ACL entry @return [Boolean] is this the owner entry

# File lib/ood_support/acls/posix.rb, line 230
def user_owner_entry?
  user_entry? && principle.empty?
end