Exemplo n.º 1
0
    def BotoEntryToJson(cls, entry):
        """Converts a Boto ACL entry to a valid JSON dictionary."""
        acl_entry_json = {}
        # JSON API documentation uses camel case.
        scope_type_lower = entry.scope.type.lower()
        if scope_type_lower == ALL_USERS.lower():
            acl_entry_json['entity'] = 'allUsers'
        elif scope_type_lower == ALL_AUTHENTICATED_USERS.lower():
            acl_entry_json['entity'] = 'allAuthenticatedUsers'
        elif scope_type_lower == USER_BY_EMAIL.lower():
            acl_entry_json['entity'] = 'user-%s' % entry.scope.email_address
            acl_entry_json['email'] = entry.scope.email_address
        elif scope_type_lower == USER_BY_ID.lower():
            acl_entry_json['entity'] = 'user-%s' % entry.scope.id
            acl_entry_json['entityId'] = entry.scope.id
        elif scope_type_lower == GROUP_BY_EMAIL.lower():
            acl_entry_json['entity'] = 'group-%s' % entry.scope.email_address
            acl_entry_json['email'] = entry.scope.email_address
        elif scope_type_lower == GROUP_BY_ID.lower():
            acl_entry_json['entity'] = 'group-%s' % entry.scope.id
            acl_entry_json['entityId'] = entry.scope.id
        elif scope_type_lower == GROUP_BY_DOMAIN.lower():
            acl_entry_json['entity'] = 'domain-%s' % entry.scope.domain
            acl_entry_json['domain'] = entry.scope.domain
        else:
            raise ArgumentException('ACL contains invalid scope type: %s' %
                                    scope_type_lower)

        acl_entry_json['role'] = cls.XML_TO_JSON_ROLES[entry.permission]
        return acl_entry_json
Exemplo n.º 2
0
 def BotoEntryFromJson(cls, entry_json):
     """Converts a JSON entry into a Boto ACL entry."""
     entity = entry_json['entity']
     permission = cls.JSON_TO_XML_ROLES[entry_json['role']]
     if entity.lower() == ALL_USERS.lower():
         return Entry(type=ALL_USERS, permission=permission)
     elif entity.lower() == ALL_AUTHENTICATED_USERS.lower():
         return Entry(type=ALL_AUTHENTICATED_USERS, permission=permission)
     elif entity.startswith('project'):
         raise CommandException('XML API does not support project scopes, '
                                'cannot translate ACL.')
     elif 'email' in entry_json:
         if entity.startswith('user'):
             scope_type = USER_BY_EMAIL
         elif entity.startswith('group'):
             scope_type = GROUP_BY_EMAIL
         return Entry(type=scope_type,
                      email_address=entry_json['email'],
                      permission=permission)
     elif 'entityId' in entry_json:
         if entity.startswith('user'):
             scope_type = USER_BY_ID
         elif entity.startswith('group'):
             scope_type = GROUP_BY_ID
         return Entry(type=scope_type,
                      id=entry_json['entityId'],
                      permission=permission)
     elif 'domain' in entry_json:
         if entity.startswith('domain'):
             scope_type = GROUP_BY_DOMAIN
         return Entry(type=scope_type,
                      domain=entry_json['domain'],
                      permission=permission)
     raise CommandException('Failed to translate JSON ACL to XML.')
Exemplo n.º 3
0
 def BotoEntryFromJson(cls, entry_json):
   """Converts a JSON entry into a Boto ACL entry."""
   entity = entry_json['entity']
   permission = cls.JSON_TO_XML_ROLES[entry_json['role']]
   if entity.lower() == ALL_USERS.lower():
     return Entry(type=ALL_USERS, permission=permission)
   elif entity.lower() == ALL_AUTHENTICATED_USERS.lower():
     return Entry(type=ALL_AUTHENTICATED_USERS, permission=permission)
   elif 'email' in entry_json:
     if entity.startswith('user'):
       scope_type = USER_BY_EMAIL
     elif entity.startswith('group'):
       scope_type = GROUP_BY_EMAIL
     return Entry(type=scope_type, email_address=entry_json['email'],
                  permission=permission)
   elif 'entityId' in entry_json:
     if entity.startswith('user'):
       scope_type = USER_BY_ID
     elif entity.startswith('group'):
       scope_type = GROUP_BY_ID
     return Entry(type=scope_type, id=entry_json['entityId'],
                  permission=permission)
   elif 'domain' in entry_json:
     if entity.startswith('domain'):
       scope_type = GROUP_BY_DOMAIN
     return Entry(type=scope_type, domain=entry_json['domain'],
                  permission=permission)
   elif 'project' in entry_json:
     if entity.startswith('project'):
       raise CommandException('XML API does not support project scopes, '
                              'cannot translate ACL.')
   raise CommandException('Failed to translate JSON ACL to XML.')
Exemplo n.º 4
0
  def BotoEntryToJson(cls, entry):
    """Converts a Boto ACL entry to a valid JSON dictionary."""
    acl_entry_json = {}
    # JSON API documentation uses camel case.
    scope_type_lower = entry.scope.type.lower()
    if scope_type_lower == ALL_USERS.lower():
      acl_entry_json['entity'] = 'allUsers'
    elif scope_type_lower == ALL_AUTHENTICATED_USERS.lower():
      acl_entry_json['entity'] = 'allAuthenticatedUsers'
    elif scope_type_lower == USER_BY_EMAIL.lower():
      acl_entry_json['entity'] = 'user-%s' % entry.scope.email_address
      acl_entry_json['email'] = entry.scope.email_address
    elif scope_type_lower == USER_BY_ID.lower():
      acl_entry_json['entity'] = 'user-%s' % entry.scope.id
      acl_entry_json['entityId'] = entry.scope.id
    elif scope_type_lower == GROUP_BY_EMAIL.lower():
      acl_entry_json['entity'] = 'group-%s' % entry.scope.email_address
      acl_entry_json['email'] = entry.scope.email_address
    elif scope_type_lower == GROUP_BY_ID.lower():
      acl_entry_json['entity'] = 'group-%s' % entry.scope.id
      acl_entry_json['entityId'] = entry.scope.id
    elif scope_type_lower == GROUP_BY_DOMAIN.lower():
      acl_entry_json['entity'] = 'domain-%s' % entry.scope.domain
      acl_entry_json['domain'] = entry.scope.domain
    else:
      raise ArgumentException('ACL contains invalid scope type: %s' %
                              scope_type_lower)

    acl_entry_json['role'] = cls.XML_TO_JSON_ROLES[entry.permission]
    return acl_entry_json
 def BotoEntryFromJson(cls, entry_json):
     """Converts a JSON entry into a Boto ACL entry."""
     entity = entry_json["entity"]
     permission = cls.JSON_TO_XML_ROLES[entry_json["role"]]
     if entity.lower() == ALL_USERS.lower():
         return Entry(type=ALL_USERS, permission=permission)
     elif entity.lower() == ALL_AUTHENTICATED_USERS.lower():
         return Entry(type=ALL_AUTHENTICATED_USERS, permission=permission)
     elif entity.startswith("project"):
         raise CommandException("XML API does not support project scopes, " "cannot translate ACL.")
     elif "email" in entry_json:
         if entity.startswith("user"):
             scope_type = USER_BY_EMAIL
         elif entity.startswith("group"):
             scope_type = GROUP_BY_EMAIL
         return Entry(type=scope_type, email_address=entry_json["email"], permission=permission)
     elif "entityId" in entry_json:
         if entity.startswith("user"):
             scope_type = USER_BY_ID
         elif entity.startswith("group"):
             scope_type = GROUP_BY_ID
         return Entry(type=scope_type, id=entry_json["entityId"], permission=permission)
     elif "domain" in entry_json:
         if entity.startswith("domain"):
             scope_type = GROUP_BY_DOMAIN
         return Entry(type=scope_type, domain=entry_json["domain"], permission=permission)
     raise CommandException("Failed to translate JSON ACL to XML.")