Class: OodSupport::ACLs::PosixEntry
- Inherits:
-
OodSupport::ACLEntry
- Object
- OodSupport::ACLEntry
- OodSupport::ACLs::PosixEntry
- 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
-
#default ⇒ Boolean
readonly
Is this a default ACL entry.
-
#flag ⇒ Symbol
readonly
Flag set on ACL entry.
-
#permissions ⇒ Array<Symbol>
readonly
Permissions of ACL entry.
Attributes inherited from OodSupport::ACLEntry
Instance Method Summary collapse
-
#default_entry? ⇒ Boolean
Is this a default ACL entry.
-
#group_entry? ⇒ Boolean
Is this a group-specific ACL entry.
-
#group_owner_entry? ⇒ Boolean
Is this the owning group ACL entry.
-
#has_permission?(permission:, mask:) ⇒ Boolean
Does this entry have the requested permission.
-
#initialize(default: false, flag:, permissions:, **kwargs) ⇒ PosixEntry
constructor
A new instance of PosixEntry.
-
#match(principle:, owner:, group:) ⇒ Boolean
Do the requested args match this ACL entry?.
-
#other_entry? ⇒ Boolean
Is this an other-specific ACL entry.
-
#to_s(w_perms: true) ⇒ String
Convert object to string.
-
#user_entry? ⇒ Boolean
Is this a user-specific ACL entry.
-
#user_owner_entry? ⇒ Boolean
Is this the owner ACL entry.
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.
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 = .map(&:to_sym) super(kwargs) end |
Instance Attribute Details
#default ⇒ Boolean (readonly)
Is this a default ACL entry
160 161 162 |
# File 'lib/ood_support/acls/posix.rb', line 160 def default @default end |
#flag ⇒ Symbol (readonly)
Flag set on ACL entry
164 165 166 |
# File 'lib/ood_support/acls/posix.rb', line 164 def flag @flag end |
#permissions ⇒ Array<Symbol> (readonly)
Permissions of ACL entry
168 169 170 |
# File 'lib/ood_support/acls/posix.rb', line 168 def @permissions end |
Instance Method Details
#default_entry? ⇒ Boolean
Is this a default ACL 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
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
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
244 245 246 247 248 249 250 |
# File 'lib/ood_support/acls/posix.rb', line 244 def (permission:, mask:) if user_owner_entry? || other_entry? .include? .to_sym else (mask ? & mask. : ).include? .to_sym end end |
#match(principle:, owner:, group:) ⇒ Boolean
Do the requested args match this ACL entry?
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
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
255 256 257 |
# File 'lib/ood_support/acls/posix.rb', line 255 def to_s(w_perms: true) %[#{"default:" if default_entry?}#{flag}:#{principle}#{":#{.join}" if w_perms}] end |
#user_entry? ⇒ Boolean
Is this a user-specific ACL 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
230 231 232 |
# File 'lib/ood_support/acls/posix.rb', line 230 def user_owner_entry? user_entry? && principle.empty? end |