Class: S33r::S3ACL::Grant
- Inherits:
-
Object
- Object
- S33r::S3ACL::Grant
- Defined in:
- lib/s33r/s3_acl.rb,
lib/s33r/s3_logging.rb
Overview
Representation of an S3 Grant (see docs.amazonwebservices.com/AmazonS3/2006-03-01/UsingGrantees.html).
A Grant consists of a Grantee and a permission they are to be assigned.
Instance Attribute Summary collapse
-
#grantee ⇒ Object
Returns the value of attribute grantee.
-
#permission ⇒ Object
Returns the value of attribute permission.
Class Method Summary collapse
-
.for_amazon_customer(email_address, permission) ⇒ Object
Note that setting a grant for an Amazon customer is the same as setting a grant for the CanonicalUser who owns the specified email address.
- .for_canonical_user(id, display_name, permission) ⇒ Object
- .for_group(group_type, permission) ⇒ Object
-
.log_target_grants ⇒ Object
Generator for a grant which gives the LogDelivery group write and read_acl permissions on a bucket.
-
.public_read_grant ⇒ Object
Generator for a Grant which gives READ permissions to the AllUsers group type.
Instance Method Summary collapse
- #==(obj) ⇒ Object
-
#initialize(grantee, permission) ⇒ Grant
constructor
permission: one of the keys in the PERMISSIONS hash or a raw permission string.
- #to_s ⇒ Object
-
#to_xml ⇒ Object
Convert a Grant object into an XML fragment.
Constructor Details
#initialize(grantee, permission) ⇒ Grant
permission: one of the keys in the PERMISSIONS hash or a raw permission string
133 134 135 136 137 138 139 140 141 142 |
# File 'lib/s33r/s3_acl.rb', line 133 def initialize(grantee, ) @grantee = grantee if .is_a? String @permission = else @permission = PERMISSIONS[] end raise InvalidPermission, \ "Permission #{.to_s} is not a valid permission specifier" if @permission.nil? end |
Instance Attribute Details
#grantee ⇒ Object
Returns the value of attribute grantee.
130 131 132 |
# File 'lib/s33r/s3_acl.rb', line 130 def grantee @grantee end |
#permission ⇒ Object
Returns the value of attribute permission.
130 131 132 |
# File 'lib/s33r/s3_acl.rb', line 130 def @permission end |
Class Method Details
.for_amazon_customer(email_address, permission) ⇒ Object
Note that setting a grant for an Amazon customer is the same as setting a grant for the CanonicalUser who owns the specified email address. So when you get the ACL back, it will actually contain a CanonicalUser grant.
148 149 150 |
# File 'lib/s33r/s3_acl.rb', line 148 def Grant.for_amazon_customer(email_address, ) Grant.new(AmazonCustomer.new(email_address), ) end |
.for_canonical_user(id, display_name, permission) ⇒ Object
152 153 154 |
# File 'lib/s33r/s3_acl.rb', line 152 def Grant.for_canonical_user(id, display_name, ) Grant.new(CanonicalUser.new(id, display_name), ) end |
.for_group(group_type, permission) ⇒ Object
156 157 158 |
# File 'lib/s33r/s3_acl.rb', line 156 def Grant.for_group(group_type, ) Grant.new(Group.new(group_type), ) end |
.log_target_grants ⇒ Object
Generator for a grant which gives the LogDelivery group write and read_acl permissions on a bucket.
Returns an array with the two required Grant instances.
106 107 108 109 |
# File 'lib/s33r/s3_logging.rb', line 106 def Grant.log_target_grants log_delivery_group = Group.new(:log_delivery) [Grant.new(log_delivery_group, :read_acl), Grant.new(log_delivery_group, :write)] end |
Instance Method Details
#==(obj) ⇒ Object
190 191 192 193 194 195 196 197 198 |
# File 'lib/s33r/s3_acl.rb', line 190 def ==(obj) if !obj.is_a?(Grant) return false end if obj. != self. or obj.grantee != self.grantee return false end return true end |
#to_s ⇒ Object
200 201 202 |
# File 'lib/s33r/s3_acl.rb', line 200 def to_s "#{@grantee.to_s} has permission #{@permission}" end |
#to_xml ⇒ Object
Convert a Grant object into an XML fragment.
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/s33r/s3_acl.rb', line 167 def to_xml xml_str = "" xml = S33r::OrderlyXmlMarkup.new(:target => xml_str, :indent => 0) # <Grant> element. xml.Grant { xml.Grantee({"xmlns:#{NAMESPACE}" => NAMESPACE_URI, "xsi:type" => @grantee.grantee_type}) { case @grantee.grantee_type when GRANTEE_TYPES[:amazon_customer] xml.EmailAddress @grantee.email_address when GRANTEE_TYPES[:canonical_user] xml.ID @grantee.user_id xml.DisplayName @grantee.display_name when GRANTEE_TYPES[:group] xml.URI GROUP_ACL_URI_BASE + @grantee.group_type end } xml.Permission @permission } xml_str end |