Beispiel #1
0
 def startElement(self, name, attrs, connection):
     if name.lower() == SCOPE.lower():
         # The following if statement used to look like this: 
         #   if not TYPE in attrs:
         # which caused problems because older versions of the 
         # AttributesImpl class in the xml.sax library neglected to include 
         # a __contains__() method (which Python calls to implement the 
         # 'in' operator). So when you use the in operator, like the if
         # statement above, Python invokes the __getiter__() method with
         # index 0, which raises an exception. More recent versions of 
         # xml.sax include the __contains__() method, rendering the in 
         # operator functional. The work-around here is to formulate the
         # if statement as below, which is the legal way to query 
         # AttributesImpl for containment (and is also how the added
         # __contains__() method works). At one time gsutil disallowed
         # xmlplus-based parsers, until this more specific problem was 
         # determined.
         if TYPE not in attrs:
             raise InvalidAclError('Missing "%s" in "%s" part of ACL' %
                                   (TYPE, SCOPE))
         self.scope = Scope(self, attrs[TYPE])
         return self.scope
     elif name.lower() == PERMISSION.lower():
         pass
     else:
         return None
Beispiel #2
0
 def endElement(self, name, value, connection):
     if name.lower() == SCOPE.lower():
         pass
     elif name.lower() == PERMISSION.lower():
         value = value.strip()
         if not value in SupportedPermissions:
             raise InvalidAclError('Invalid Permission "%s"' % value)
         self.permission = value
     else:
         setattr(self, name, value)
Beispiel #3
0
 def __init__(self, parent, type=None, id=None, name=None,
              email_address=None, domain=None):
     self.parent = parent
     self.type = type
     self.name = name
     self.id = id
     self.domain = domain
     self.email_address = email_address
     if self.type.lower() not in self.ALLOWED_SCOPE_TYPE_SUB_ELEMS:
         raise InvalidAclError('Invalid %s %s "%s" ' %
                               (SCOPE, TYPE, self.type))
Beispiel #4
0
    def set_acl(self,
                acl_or_str,
                key_name='',
                headers=None,
                version_id=None,
                generation=None,
                if_generation=None,
                if_metageneration=None):
        """Sets or changes a bucket's or key's ACL.

        :type acl_or_str: string or :class:`fcu_boto.gs.acl.ACL`
        :param acl_or_str: A canned ACL string (see
            :data:`~.gs.acl.CannedACLStrings`) or an ACL object.

        :type key_name: string
        :param key_name: A key name within the bucket to set the ACL for. If not
            specified, the ACL for the bucket will be set.

        :type headers: dict
        :param headers: Additional headers to set during the request.

        :type version_id: string
        :param version_id: Unused in this subclass.

        :type generation: int
        :param generation: If specified, sets the ACL for a specific generation
            of a versioned object. If not specified, the current version is
            modified.

        :type if_generation: int
        :param if_generation: (optional) If set to a generation number, the acl
            will only be updated if its current generation number is this value.

        :type if_metageneration: int
        :param if_metageneration: (optional) If set to a metageneration number,
            the acl will only be updated if its current metageneration number is
            this value.
        """
        if isinstance(acl_or_str, Policy):
            raise InvalidAclError('Attempt to set S3 Policy on GS ACL')
        elif isinstance(acl_or_str, ACL):
            self.set_xml_acl(acl_or_str.to_xml(),
                             key_name,
                             headers=headers,
                             generation=generation,
                             if_generation=if_generation,
                             if_metageneration=if_metageneration)
        else:
            self.set_canned_acl(acl_or_str,
                                key_name,
                                headers=headers,
                                generation=generation,
                                if_generation=if_generation,
                                if_metageneration=if_metageneration)
Beispiel #5
0
    def set_def_acl(self, acl_or_str, headers=None):
        """Sets or changes a bucket's default ACL.

        :type acl_or_str: string or :class:`fcu_boto.gs.acl.ACL`
        :param acl_or_str: A canned ACL string (see
            :data:`~.gs.acl.CannedACLStrings`) or an ACL object.

        :type headers: dict
        :param headers: Additional headers to set during the request.
        """
        if isinstance(acl_or_str, Policy):
            raise InvalidAclError('Attempt to set S3 Policy on GS ACL')
        elif isinstance(acl_or_str, ACL):
            self.set_def_xml_acl(acl_or_str.to_xml(), headers=headers)
        else:
            self.set_def_canned_acl(acl_or_str, headers=headers)
Beispiel #6
0
    def to_xml(self):
        s = '<%s type="%s">' % (SCOPE, self.type)
        if (self.type.lower() == ALL_AUTHENTICATED_USERS.lower()
            or self.type.lower() == ALL_USERS.lower()):
            pass
        elif self.type.lower() == GROUP_BY_DOMAIN.lower():
            s += '<%s>%s</%s>' % (DOMAIN, self.domain, DOMAIN)
        elif (self.type.lower() == GROUP_BY_EMAIL.lower()
              or self.type.lower() == USER_BY_EMAIL.lower()):
            s += '<%s>%s</%s>' % (EMAIL_ADDRESS, self.email_address,
                                  EMAIL_ADDRESS)
            if self.name:
              s += '<%s>%s</%s>' % (NAME, self.name, NAME)
        elif (self.type.lower() == GROUP_BY_ID.lower()
              or self.type.lower() == USER_BY_ID.lower()):
            s += '<%s>%s</%s>' % (ID, self.id, ID)
            if self.name:
              s += '<%s>%s</%s>' % (NAME, self.name, NAME)
        else:
            raise InvalidAclError('Invalid scope type "%s" ', self.type)

        s += '</%s>' % SCOPE
        return s
Beispiel #7
0
 def startElement(self, name, attrs, connection):
     if (not name.lower() in
         self.ALLOWED_SCOPE_TYPE_SUB_ELEMS[self.type.lower()]):
         raise InvalidAclError('Element "%s" not allowed in %s %s "%s" ' %
                                (name, SCOPE, TYPE, self.type))
     return None