Class: HP::Cloud::Acl
- Inherits:
-
Object
- Object
- HP::Cloud::Acl
- Defined in:
- lib/hpcloud/acl.rb
Constant Summary collapse
- ALL =
".r:*,.rlistings"
Instance Attribute Summary collapse
-
#cstatus ⇒ Object
readonly
Returns the value of attribute cstatus.
-
#public ⇒ Object
readonly
Returns the value of attribute public.
-
#users ⇒ Object
readonly
Returns the value of attribute users.
Instance Method Summary collapse
- #grant(ray) ⇒ Object
-
#initialize(key, hash) ⇒ Acl
constructor
A new instance of Acl.
- #is_valid? ⇒ Boolean
- #parse_acl(header) ⇒ Object
- #parse_public(header) ⇒ Object
- #revoke(ray) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
Instance Attribute Details
#cstatus ⇒ Object (readonly)
Returns the value of attribute cstatus.
27 28 29 |
# File 'lib/hpcloud/acl.rb', line 27 def cstatus @cstatus end |
#public ⇒ Object (readonly)
Returns the value of attribute public.
27 28 29 |
# File 'lib/hpcloud/acl.rb', line 27 def public @public end |
#users ⇒ Object (readonly)
Returns the value of attribute users.
27 28 29 |
# File 'lib/hpcloud/acl.rb', line 27 def users @users end |
Instance Method Details
#grant(ray) ⇒ Object
68 69 70 71 72 |
# File 'lib/hpcloud/acl.rb', line 68 def grant(ray) return true if ray.nil? @users = ray return true end |
#is_valid? ⇒ Boolean
58 59 60 |
# File 'lib/hpcloud/acl.rb', line 58 def is_valid? return @cstatus.is_success? end |
#parse_acl(header) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/hpcloud/acl.rb', line 37 def parse_acl(header) return nil if header.nil? return [] if header.start_with?(".r:*") ray = [] header.split(",").each {|x| if x.index(":") u = x.split(":")[1] ray << u unless u.nil? else ray << x end } return nil if ray.empty? return ray end |
#parse_public(header) ⇒ Object
53 54 55 56 |
# File 'lib/hpcloud/acl.rb', line 53 def parse_public(header) return "no" if header.nil? return header.start_with?(".r:*")?"yes":"no" end |
#revoke(ray) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/hpcloud/acl.rb', line 74 def revoke(ray) if ray.nil? @users = nil return true end return true if ray.empty? not_found = [] if @users.nil? not_found << ray else ray.each{ |x| if @users.delete(x).nil? rc = false not_found << x end } end @users = nil if @users.nil? || @users.empty? return true if not_found.empty? @cstatus = CliStatus.new("Revoke failed invalid user: #{not_found.join(',')}", :not_found) return false end |
#to_hash ⇒ Object
62 63 64 65 66 |
# File 'lib/hpcloud/acl.rb', line 62 def to_hash return { } if @users.nil? return { @key => ALL } if @users.empty? return { @key => "*:" + @users.join(",*:") } end |