Class: OodSupport::ACLs::PosixEntry

Inherits:
OodSupport::ACLEntry show all
Defined in:
lib/ood_support/acls/posix.rb

Overview

Object describing single Posix ACL entry

Constant Summary collapse

VALID_FLAG =

Valid flags for an ACL entry

%i[ user group mask other ]
VALID_PERMISSION =

Valid permissions for an ACL entry

%i[ r w x ]
REGEX_PATTERN =

Regular expression used when parsing ACL entry string

%r[^(?<default>default:)?(?<flag>#{VALID_FLAG.join('|')}):(?<principle>\w*):(?<permissions>[#{VALID_PERMISSION.join}\-]{3})]

Instance Attribute Summary collapse

Attributes inherited from OodSupport::ACLEntry

#principle

Instance Method Summary collapse

Methods inherited from OodSupport::ACLEntry

#<=>, #eql?, #hash, #is_allow?, #is_deny?, parse

Constructor Details

#initialize(default: false, flag:, permissions:, **kwargs) ⇒ PosixEntry

Returns a new instance of PosixEntry.

Parameters:

  • default (Boolean) (defaults to: false)

    whether default acl entry

  • flag (#to_sym)

    flag for entry

  • permissions (Array<#to_sym>)

    list of permissions for entry

See Also:



174
175
176
177
178
179
# 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

Instance Attribute Details

#defaultBoolean (readonly)

Is this a default ACL entry

Returns:

  • (Boolean)

    whether default acl entry



160
161
162
# File 'lib/ood_support/acls/posix.rb', line 160

def default
  @default
end

#flagSymbol (readonly)

Flag set on ACL entry

Returns:

  • (Symbol)

    flag on acl entry



164
165
166
# File 'lib/ood_support/acls/posix.rb', line 164

def flag
  @flag
end

#permissionsArray<Symbol> (readonly)

Permissions of ACL entry

Returns:

  • (Array<Symbol>)

    permissions of acl entry



168
169
170
# File 'lib/ood_support/acls/posix.rb', line 168

def permissions
  @permissions
end

Instance Method Details

#default_entry?Boolean

Is this a default ACL entry

Returns:

  • (Boolean)

    is this a default entry



206
207
208
# File 'lib/ood_support/acls/posix.rb', line 206

def default_entry?
  default
end

#group_entry?Boolean

Is this a group-specific ACL entry

Returns:

  • (Boolean)

    is this a group entry



218
219
220
# File 'lib/ood_support/acls/posix.rb', line 218

def group_entry?
  !default_entry? && flag == :group
end

#group_owner_entry?Boolean

Is this the owning group ACL entry

Returns:

  • (Boolean)

    is this the owning group entry



236
237
238
# File 'lib/ood_support/acls/posix.rb', line 236

def group_owner_entry?
  group_entry? && principle.empty?
end

#has_permission?(permission:, mask:) ⇒ Boolean

Does this entry have the requested permission

Parameters:

  • permission (#to_sym)

    the requested permission

  • mask (PosixEntry)

    the permissions of the mask entry

Returns:

  • (Boolean)

    found this permission



244
245
246
247
248
249
250
# 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:) ⇒ Boolean

Do the requested args match this ACL entry?

Parameters:

  • principle (User, Group, #to_s)

    requested principle

  • owner (String)

    owner of corresponding ACL

  • group (String)

    owning group of corresponding ACL

Returns:

  • (Boolean)

    does this match this entry

Raises:

  • (ArgumentError)

    principle isn’t User or Group object



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# 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?Boolean

Is this an other-specific ACL entry

Returns:

  • (Boolean)

    is this an other entry



224
225
226
# File 'lib/ood_support/acls/posix.rb', line 224

def other_entry?
  !default_entry? && flag == :other
end

#to_s(w_perms: true) ⇒ String

Convert object to string

Parameters:

  • w_perms (Boolean) (defaults to: true)

    whether display permissions

Returns:

  • (String)

    the string describing this object



255
256
257
# 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?Boolean

Is this a user-specific ACL entry

Returns:

  • (Boolean)

    is this a user entry



212
213
214
# File 'lib/ood_support/acls/posix.rb', line 212

def user_entry?
  !default_entry? && flag == :user
end

#user_owner_entry?Boolean

Is this the owner ACL entry

Returns:

  • (Boolean)

    is this the owner entry



230
231
232
# File 'lib/ood_support/acls/posix.rb', line 230

def user_owner_entry?
  user_entry? && principle.empty?
end