Class: OodSupport::ACLs::Nfs4Entry

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

Overview

Object describing single NFSv4 ACL entry

Constant Summary collapse

VALID_TYPE =

Valid types for an ACL entry

A U D L
VALID_FLAG =

Valid flags for an ACL entry

f d p i S F g
VALID_PERMISSION =

Valid permissions for an ACL entry

r w a x d D t T n N c C o y
REGEX_PATTERN =

Regular expression used when parsing ACL entry string

%r[^(?<type>[#{VALID_TYPE.join}]):(?<flags>[#{VALID_FLAG.join}]*):(?<principle>\w+)@(?<domain>[\w\.\-]*):(?<permissions>[#{VALID_PERMISSION.join}]+)$]

Instance Attribute Summary collapse

Attributes inherited from OodSupport::ACLEntry

#principle

Instance Method Summary collapse

Methods inherited from OodSupport::ACLEntry

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

Constructor Details

#initialize(type:, flags:, domain:, permissions:, **kwargs) ⇒ Nfs4Entry

Returns a new instance of Nfs4Entry


158
159
160
161
162
163
164
# File 'lib/ood_support/acls/nfs4.rb', line 158

def initialize(type:, flags:, domain:, permissions:, **kwargs)
  @type = type.to_sym
  @flags = flags.map(&:to_sym)
  @domain = domain.to_s
  @permissions = permissions.map(&:to_sym)
  super(kwargs)
end

Instance Attribute Details

#domainString (readonly)

Domain of ACL entry


147
148
149
# File 'lib/ood_support/acls/nfs4.rb', line 147

def domain
  @domain
end

#flagsArray<Symbol> (readonly)

Flags set on ACL entry


143
144
145
# File 'lib/ood_support/acls/nfs4.rb', line 143

def flags
  @flags
end

#permissionsArray<Symbol> (readonly)

Permissions of ACL entry


151
152
153
# File 'lib/ood_support/acls/nfs4.rb', line 151

def permissions
  @permissions
end

#typeSymbol (readonly)

Type of ACL entry


139
140
141
# File 'lib/ood_support/acls/nfs4.rb', line 139

def type
  @type
end

Instance Method Details

#group_entry?Boolean

Is this a group-specific ACL entry


211
212
213
# File 'lib/ood_support/acls/nfs4.rb', line 211

def group_entry?
  flags.include? :g
end

#group_owner_entry?Boolean

Is this the owning group ACL entry


229
230
231
# File 'lib/ood_support/acls/nfs4.rb', line 229

def group_owner_entry?
  group_entry? && principle == "GROUP"
end

#has_permission?(permission:) ⇒ Boolean

Does this entry have the requested permission


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

def has_permission?(permission:)
  permissions.include? permission.to_sym
end

#is_allow?Boolean

Is this an “allow” ACL entry


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

def is_allow?
  type == :A
end

#is_deny?Boolean

Is this a “deny” ACL entry


174
175
176
# File 'lib/ood_support/acls/nfs4.rb', line 174

def is_deny?
  type == :D
end

#match(principle:, permission:, owner:, group:) ⇒ Boolean

Do the requested args match this ACL entry?

Raises:

  • (ArgumentError)

    principle isn't User or Group object


185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/ood_support/acls/nfs4.rb', line 185

def match(principle:, permission:, owner:, group:)
  principle = User.new(principle) if (!principle.is_a?(User) && !principle.is_a?(Group))
  return false unless has_permission?(permission: permission)
  # Ignore domain, I don't want or care to check for domain matches
  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


217
218
219
# File 'lib/ood_support/acls/nfs4.rb', line 217

def other_entry?
  principle == "EVERYONE"
end

#to_sString

Convert object to string


242
243
244
# File 'lib/ood_support/acls/nfs4.rb', line 242

def to_s
  "#{type}:#{flags.join}:#{principle}@#{domain}:#{permissions.join}"
end

#user_entry?Boolean

Is this a user-specific ACL entry


205
206
207
# File 'lib/ood_support/acls/nfs4.rb', line 205

def user_entry?
  !group_entry? && !other_entry?
end

#user_owner_entry?Boolean

Is this the owner ACL entry


223
224
225
# File 'lib/ood_support/acls/nfs4.rb', line 223

def user_owner_entry?
  user_entry? && principle == "OWNER"
end