Class: S33r::S3ACL::Grant
- Inherits:
-
Object
- Object
- S33r::S3ACL::Grant
- Defined in:
- lib/s33r/s3_acl.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_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
166 167 168 169 170 171 172 173 174 |
# File 'lib/s33r/s3_acl.rb', line 166 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.
163 164 165 |
# File 'lib/s33r/s3_acl.rb', line 163 def grantee @grantee end |
#permission ⇒ Object
Returns the value of attribute permission.
163 164 165 |
# File 'lib/s33r/s3_acl.rb', line 163 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.
180 181 182 |
# File 'lib/s33r/s3_acl.rb', line 180 def Grant.for_amazon_customer(email_address, ) Grant.new(AmazonCustomer.new(email_address), ) end |
.for_canonical_user(id, display_name, permission) ⇒ Object
184 185 186 |
# File 'lib/s33r/s3_acl.rb', line 184 def Grant.for_canonical_user(id, display_name, ) Grant.new(CanonicalUser.new(id, display_name), ) end |
.for_group(group_type, permission) ⇒ Object
188 189 190 |
# File 'lib/s33r/s3_acl.rb', line 188 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.
202 203 204 205 |
# File 'lib/s33r/s3_acl.rb', line 202 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
231 232 233 234 235 236 237 238 239 |
# File 'lib/s33r/s3_acl.rb', line 231 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_xml ⇒ Object
Convert a Grant object into an XML fragment.
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/s33r/s3_acl.rb', line 208 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 |