module AWS::S3::ACLOptions
def acl_options acl
-
(Hash)
- Returns a hash of options suitable for
Parameters:
-
acl
(Symbol, String, Hash, AccessControlList
) -- Accepts an ACL
def acl_options acl case acl when Symbol { :acl => acl.to_s.tr('_', '-') } when String # Strings are either access control policies (xml strings) # or they are canned acls xml?(acl) ? { :access_control_policy => acl } : { :acl => acl } when AccessControlList { :access_control_policy => acl.to_xml } when Hash # Hashes are either grant hashes or constructor args for an # access control list (deprecated) grant_hash?(acl) ? format_grants(acl) : { :access_control_policy => AccessControlList.new(acl).to_xml } else # failed to parse the acl option msg = "expected a canned ACL, AccessControlList object, ACL " "XML string or a grants hash" raise ArgumentError, msg end end
def format_grantee grantee
def format_grantee grantee case grantee when String then grantee when Hash if grantee.keys.count != 1 msg = "grantee hashes must have exactly 1 key" raise ArgumentError, msg end # A granee hash looks like: # { :id => 'abc...fec' } # { :uri => 'http://abc.com/foo' } # { :email_address => 'xyz@amazon.com } # # It needs to look like # 'id="abc...fec"' # 'uri="http://abc.com/foo"' # 'emailAddress="xyz@amazon.com"' type, token = grantee.to_a.flatten type = type.to_s.split('_').map{|part| ucfirst(part) }.join "#{type[0,1].downcase}#{type[1..-1]}=\"#{token}\"" else raise ArgumentError, "grantees must be a string or a hash" end end
def format_grants acl_hash
-
(Hash)
- Returns a hash of grant options suitable for
Parameters:
-
acl_hash
(Hash
) --
def format_grants acl_hash grants = {} acl_hash.each_pair do |grant,grantees| grantees = [grantees] unless grantees.is_a?(Array) grants[grant] = grantees.map{|g| format_grantee(g) }.join(', ') end grants end
def grant_hash? acl_hash
-
(Boolean)
- Retursn +true+ if this hash is a hash of grants.
Parameters:
-
acl_hash
(Hash
) --
def grant_hash? acl_hash grant_keys = [ :grant_read, :grant_write, :grant_read_acp, :grant_write_acp, :grant_full_control, ] acl_hash.keys.all?{|key| grant_keys.include?(key) } end
def ucfirst str
def ucfirst str str[0,1].upcase + str[1..-1] end
def xml? acl_string
-
(Boolean)
- Returns +true+ if this string is an xml document.
Parameters:
-
acl_string
(String
) --
def xml? acl_string begin REXML::Document.new(acl_string).has_elements? rescue false end end