class Atmos::ACL

Access Control Lists (ACLs)

There are two hashes for access control, available as properties on the object: user_acl and group_acl.

The keys are the Atmos usernames and the values are one of :none, :read, :write, :full. The ACLs behave like normal Hash objects. All operations are executed against the Atmos server immediately.

Defaults

By default, when you create an object, the user you gave as a parameter when instantiating Atmos::Store has full permissions on the object The default group is other. So:

puts obj.user_acl.inspect => {user => :full}
puts obj.group_acl.inspect => {other => :none}

Adding

Adding permissions for a new user is as easy as adding another hash element:

obj.user_acl[newuser] = :read

puts obj.user_acl.inspect => {user => :full, newuser => :read}

Modifying

User and group permissions can be modified by modifying the appropriate key value. Keep in mind that you CAN be dumb and give up access to your own objects, even if there is no other user that has access to them.

obj.user_acl[newuser] = :full
puts obj.user_acl.inspect => {user => :full, newuser => :full}

obj.group_acl['other'] = :full
puts obj.group_acl.inspect => {other => :full}

Deleting

Remove any permissions for a given user or group, you can either modify existing permissions to :none, or you can delete the user/group name from the appropriate hash. When you do either, the name disappears entirely from the hash.

obj.user_acl.delete(newuser)
puts obj.user_acl.inspect => {user => :full}

obj.user_acl[newuser] = :none
puts obj.user_acl.inspect => {user => :full}

Constants

GROUP
USER

Public Class Methods

new(obj, type) click to toggle source

This constructor is only meant for internal use. To get ACLs on an object:

obj.user_acl => Hash
obj.group_acl => Hash
Calls superclass method
# File lib/atmos/attributes.rb, line 202
def initialize(obj, type)
   raise Atmos::Exceptions::ArgumentException, "The 'obj' parameter cannot be nil." if (obj.nil?)
   raise Atmos::Exceptions::ArgumentException, "The 'obj' parameter must have an id." if (obj.aoid.nil?)
   raise Atmos::Exceptions::ArgumentException, "The 'type' parameter must be Atmos::ACL::USER or Atmos::ACL::GROUP." if (![USER, GROUP].include?(type))
   
   super()
   
   @obj = obj
   @type = type
   
   @header = (@type == USER) ? 'x-emc-useracl' : 'x-emc-groupacl'
   @delete_action = @set_action = (@type == USER) ? :set_user_acl : :set_group_acl
   @reload_action = :list_acl
   
   reload(@reload_action, @obj.aoid)
end

Public Instance Methods

[]=(key,value) click to toggle source

Adds or modifies permissions for a user or group.

The change is made on the Atmos server immediately. Valid values are :none, :read, :write, :full.

# File lib/atmos/attributes.rb, line 225
def []=(key,value)
   validate_value(value)
   response = @obj.request.do(@set_action, :id => @obj.aoid, @header => "#{key}=#{xlate_value_from_object_to_header(value)}")
   reload(@reload_action, @obj.aoid)
end
clear() click to toggle source

Removes all permissions for all groups, or for all users except the one used to instantiate the Atmos::Store connection.

# File lib/atmos/attributes.rb, line 260
def clear
   # do a reload to make absolutely sure ACL is up to date
   reload(@reload_action, @obj.aoid)
   
   values = {}
   self.each do |k,v|
      values[k] = xlate_value_from_object_to_header(:none)
   end
   values.delete(@obj.user)
   
   response = @obj.request.do(@set_action, :id => @obj.aoid, @header => Atmos::Util.hash2header(values))
   reload(@reload_action, @obj.aoid)         
end
delete(key) click to toggle source

Removes permissions for specified user/group name. Update is made on the Atmos server immediately.

# File lib/atmos/attributes.rb, line 250
def delete(key)
   response = @obj.request.do(@set_action, :id => @obj.aoid, @header => "#{key}=#{xlate_value_from_object_to_header(:none)}")
   self.delete_without_atmos(key)
   reload(@reload_action, @obj.aoid)         
end
group?() click to toggle source

Returns true if this ACL object is representing group ACLs.

# File lib/atmos/attributes.rb, line 242
def group?
   @type == GROUP
end
user?() click to toggle source

Returns true if this ACL object is representing user ACLs.

# File lib/atmos/attributes.rb, line 235
def user?
   @type == USER
end

Private Instance Methods

validate_input_hash(h) click to toggle source
# File lib/atmos/attributes.rb, line 276
def validate_input_hash(h)
   msg = nil
   bad_keys = []
   bad_values = []
   good_values = [:none, :read, :write, :full]
   
   h.each do |k,v|
      bad_keys.push(k) if (k.nil? || !k.kind_of?(String))
      bad_values.push(v) if (v.nil? || !good_values.include?(v))
   end
   
   msg = "The input has was bad: " if (!bad_keys.empty? || !bad_values.empty?)
   msg += "bad keys: #{bad_keys.inspect} " if (!bad_keys.empty?)
   msg += "bad values: #{bad_values.inspect}" if (!bad_values.empty?)
   
   raise Atmos::Exceptions::ArgumentException, msg if (!msg.nil?)
end
validate_value(value) click to toggle source
# File lib/atmos/attributes.rb, line 294
def validate_value(value)
   if (![:none, :read, :write, :full].include?(value))
      raise Atmos::Exceptions::ArgumentException, "Valid permissions values are :none, :read, :write, :full"
   end
end
xlate_value_from_header_to_object(value) click to toggle source
# File lib/atmos/attributes.rb, line 300
def xlate_value_from_header_to_object(value)
   case value
   when 'NONE'
      :none
   when 'READ'
      :read
   when 'WRITE'
      :write
   when 'FULL_CONTROL'
      :full
   else
      raise Atmos::Exceptions::InternalLibraryException, "Permissions type not recognized: #{value}"
   end
end
xlate_value_from_object_to_header(value) click to toggle source
# File lib/atmos/attributes.rb, line 315
def xlate_value_from_object_to_header(value)
   case value
   when :none
      'NONE'
   when :read
      'READ'
   when :write
      'WRITE'
   when :full
      'FULL_CONTROL'
   end
end