Class: HP::Cloud::Acl

Inherits:
Object
  • Object
show all
Defined in:
lib/hpcloud/acl.rb

Direct Known Subclasses

AclReader, AclWriter

Constant Summary collapse

ALL =
".r:*,.rlistings"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, hash) ⇒ Acl

Returns a new instance of Acl.



29
30
31
32
33
34
35
# File 'lib/hpcloud/acl.rb', line 29

def initialize(key, hash)
  @key = key
  @cstatus = CliStatus.new
  hash = {} if hash.nil?
  @users = parse_acl(hash[key])
  @public = parse_public(hash[key])
end

Instance Attribute Details

#cstatusObject (readonly)

Returns the value of attribute cstatus.



27
28
29
# File 'lib/hpcloud/acl.rb', line 27

def cstatus
  @cstatus
end

#publicObject (readonly)

Returns the value of attribute public.



27
28
29
# File 'lib/hpcloud/acl.rb', line 27

def public
  @public
end

#usersObject (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

Returns:

  • (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_hashObject



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