Example #1
0
 def from_xml(xml_str):
     try:
         dom = etree.Element("root")
         dom.append(etree.fromstring(xml_str))
         root = dom.find("{http://docs.openstack.org/identity/api/v2.0}"
                         "auth")
         xmlns = "http://docs.openstack.org/identity/api/ext/OS-KSEC2/v1.0"
         if root is None:
             root = dom.find("{%s}ec2Credentials" % xmlns)
         else:
             root = root.find("{%s}ec2Credentials" % xmlns)
         if root is None:
             raise fault.BadRequestFault("Expecting ec2Credentials")
         access = root.get("key")
         utils.check_empty_string(access, "Expecting an access key.")
         signature = root.get("signature")
         utils.check_empty_string(signature, "Expecting a signature.")
         verb = root.get("verb")
         utils.check_empty_string(verb, "Expecting a verb.")
         host = root.get("host")
         utils.check_empty_string(signature, "Expecting a host.")
         path = root.get("path")
         utils.check_empty_string(signature, "Expecting a path.")
         # TODO(vish): parse xml params
         params = {}
         return Ec2Credentials(access, signature, verb, host, path, params)
     except etree.LxmlError as e:
         raise fault.BadRequestFault("Cannot parse password credentials",
                                     str(e))
Example #2
0
    def from_xml(xml_str):
        try:
            dom = etree.Element("root")
            dom.append(etree.fromstring(xml_str))
            root = dom.find("{http://docs.openstack.org/identity/api/v2.0}"
                            "auth")
            if root is None:
                raise fault.BadRequestFault("Expecting auth")
            tenant_id = root.get("tenantId")
            tenant_name = root.get("tenantName")
            password_credentials = \
                root.find("{http://docs.openstack.org/identity/api/v2.0}"
                "passwordCredentials")
            if password_credentials is None:
                raise fault.BadRequestFault("Expecting passwordCredentials")
            username = password_credentials.get("username")
            utils.check_empty_string(username, "Expecting a username")
            password = password_credentials.get("password")
            utils.check_empty_string(password, "Expecting a password")

            if tenant_id and tenant_name:
                raise fault.BadRequestFault(
                    "Expecting either Tenant ID or Tenant Name, but not both")

            return AuthWithPasswordCredentials(username, password, tenant_id,
                                               tenant_name)
        except etree.LxmlError as e:
            raise fault.BadRequestFault("Cannot parse password access", str(e))
Example #3
0
 def from_xml(xml_str):
     try:
         dom = etree.Element("root")
         dom.append(etree.fromstring(xml_str))
         root = dom.find("{http://docs.openstack.org/identity/api/v2.0}" "auth")
         xmlns = "http://docs.openstack.org/identity/api/ext/OS-KSEC2/v1.0"
         if root is None:
             root = dom.find("{%s}ec2Credentials" % xmlns)
         else:
             root = root.find("{%s}ec2Credentials" % xmlns)
         if root is None:
             raise fault.BadRequestFault("Expecting ec2Credentials")
         access = root.get("key")
         utils.check_empty_string(access, "Expecting an access key.")
         signature = root.get("signature")
         utils.check_empty_string(signature, "Expecting a signature.")
         verb = root.get("verb")
         utils.check_empty_string(verb, "Expecting a verb.")
         host = root.get("host")
         utils.check_empty_string(signature, "Expecting a host.")
         path = root.get("path")
         utils.check_empty_string(signature, "Expecting a path.")
         # TODO(vish): parse xml params
         params = {}
         return Ec2Credentials(access, signature, verb, host, path, params)
     except etree.LxmlError as e:
         raise fault.BadRequestFault("Cannot parse password credentials", str(e))
Example #4
0
    def from_xml(xml_str):
        try:
            dom = etree.Element("root")
            dom.append(etree.fromstring(xml_str))
            root = dom.find("{http://docs.openstack.org/identity/api/v2.0}"
                            "auth")
            if root is None:
                raise fault.BadRequestFault("Expecting auth")
            tenant_id = root.get("tenantId")
            tenant_name = root.get("tenantName")
            password_credentials = \
                root.find("{http://docs.openstack.org/identity/api/v2.0}"
                "passwordCredentials")
            if password_credentials is None:
                raise fault.BadRequestFault("Expecting passwordCredentials")
            username = password_credentials.get("username")
            utils.check_empty_string(username, "Expecting a username")
            password = password_credentials.get("password")
            utils.check_empty_string(password, "Expecting a password")

            if tenant_id and tenant_name:
                raise fault.BadRequestFault(
                    "Expecting either Tenant ID or Tenant Name, but not both")

            return AuthWithPasswordCredentials(username, password, tenant_id,
                tenant_name)
        except etree.LxmlError as e:
            raise fault.BadRequestFault("Cannot parse password access", str(e))
Example #5
0
    def from_json(json_str):
        try:
            obj = json.loads(json_str)
            if not "passwordCredentials" in obj:
                raise fault.BadRequestFault("Expecting passwordCredentials")
            password_credentials = obj["passwordCredentials"]

            user_name = password_credentials.get('username')
            password = password_credentials.get('password')
            utils.check_empty_string(password, "Expecting a password.")
            return PasswordCredentials(user_name, password)
        except (ValueError, TypeError) as e:
            raise fault.BadRequestFault(
                "Cannot parse passwordCredentials", str(e))
Example #6
0
 def from_xml(xml_str):
     try:
         dom = etree.Element("root")
         dom.append(etree.fromstring(xml_str))
         root = dom.find("{http://docs.openstack.org/identity/api/v2.0}" \
             "passwordCredentials")
         if root is None:
             raise fault.BadRequestFault("Expecting passwordCredentials")
         user_name = root.get("username")
         password = root.get("password")
         utils.check_empty_string(password, "Expecting a password.")
         return PasswordCredentials(user_name, password)
     except etree.LxmlError as e:
         raise fault.BadRequestFault("Cannot parse passwordCredentials",
                                     str(e))
Example #7
0
    def from_json(json_str):
        try:
            obj = json.loads(json_str)
            if not "role" in obj:
                raise fault.BadRequestFault("Expecting Role")
            role = obj["role"]

            id = role.get('id')
            name = role.get('name')
            description = role.get('description')
            service_id = role.get('serviceId')
            utils.check_empty_string(name, "Expecting Role name")
            return Role(id, name, description, service_id)
        except (ValueError, TypeError) as e:
            raise fault.BadRequestFault("Cannot parse Role", str(e))
Example #8
0
 def from_xml(xml_str):
     try:
         dom = etree.Element("root")
         dom.append(etree.fromstring(xml_str))
         root = dom.find("{http://docs.openstack.org/identity/api/v2.0}" \
             "passwordCredentials")
         if root is None:
             raise fault.BadRequestFault("Expecting passwordCredentials")
         user_name = root.get("username")
         password = root.get("password")
         utils.check_empty_string(password, "Expecting a password.")
         return PasswordCredentials(user_name, password)
     except etree.LxmlError as e:
         raise fault.BadRequestFault(
             "Cannot parse passwordCredentials", str(e))
Example #9
0
    def from_json(json_str):
        try:
            obj = json.loads(json_str)
            if not "OS-KSADM:service" in obj:
                raise fault.BadRequestFault("Expecting service")

            service = obj["OS-KSADM:service"]
            id = service.get('id')
            name = service.get('name')
            type = service.get('type')
            description = service.get('description')
            utils.check_empty_string(name, "Expecting Service Name")
            utils.check_empty_string(type, "Expecting Service Type")
            return Service(id, name, type, description)
        except (ValueError, TypeError) as e:
            raise fault.BadRequestFault("Cannot parse service", str(e))
Example #10
0
 def from_xml(xml_str):
     try:
         dom = etree.Element("root")
         dom.append(etree.fromstring(xml_str))
         root = dom.find("{http://docs.openstack.org/identity/api/v2.0}" \
             "role")
         if root is None:
             raise fault.BadRequestFault("Expecting Role")
         id = root.get("id")
         name = root.get("name")
         description = root.get("description")
         utils.check_empty_string(name, "Expecting Role name")
         service_id = root.get("serviceId")
         return Role(id, name, description, service_id)
     except etree.LxmlError as e:
         raise fault.BadRequestFault("Cannot parse Role", str(e))
Example #11
0
 def from_xml(xml_str):
     try:
         dom = etree.Element("root")
         dom.append(etree.fromstring(xml_str))
         root = dom.find("{http://docs.openstack.org/identity/api/v2.0}" \
             "role")
         if root is None:
             raise fault.BadRequestFault("Expecting Role")
         id = root.get("id")
         name = root.get("name")
         description = root.get("description")
         utils.check_empty_string(name, "Expecting Role name")
         service_id = root.get("serviceId")
         return Role(id, name, description, service_id)
     except etree.LxmlError as e:
         raise fault.BadRequestFault("Cannot parse Role", str(e))
Example #12
0
 def from_xml(xml_str):
     try:
         dom = etree.Element("root")
         dom.append(etree.fromstring(xml_str))
         root = dom.find(
             "{http://docs.openstack.org/identity/api/ext/OS-KSADM/v1.0}"\
             "service")
         if root is None:
             raise fault.BadRequestFault("Expecting Service")
         id = root.get("id")
         name = root.get("name")
         type = root.get("type")
         description = root.get("description")
         utils.check_empty_string(name, "Expecting Service Name")
         utils.check_empty_string(type, "Expecting Service Type")
         return Service(id, name, type, description)
     except etree.LxmlError as e:
         raise fault.BadRequestFault("Cannot parse service", str(e))
Example #13
0
    def from_json(json_str):
        try:
            obj = json.loads(json_str)
            if not "passwordCredentials" in obj:
                raise fault.BadRequestFault("Expecting passwordCredentials")
            password_credentials = obj["passwordCredentials"]

            # Check that fields are valid
            invalid = [key for key in password_credentials if key not in\
                       ['username', 'password']]
            if invalid != []:
                raise fault.BadRequestFault("Invalid attribute(s): %s" %
                                            invalid)

            user_name = password_credentials.get('username')
            password = password_credentials.get('password')
            utils.check_empty_string(password, "Expecting a password.")
            return PasswordCredentials(user_name, password)
        except (ValueError, TypeError) as e:
            raise fault.BadRequestFault("Cannot parse passwordCredentials",
                                        str(e))
Example #14
0
    def from_json(json_str):
        try:
            obj = json.loads(json_str)
            if not "passwordCredentials" in obj:
                raise fault.BadRequestFault("Expecting passwordCredentials")
            password_credentials = obj["passwordCredentials"]

            # Check that fields are valid
            invalid = [key for key in password_credentials if key not in\
                       ['username', 'password']]
            if invalid != []:
                raise fault.BadRequestFault("Invalid attribute(s): %s"
                                            % invalid)

            user_name = password_credentials.get('username')
            password = password_credentials.get('password')
            utils.check_empty_string(password, "Expecting a password.")
            return PasswordCredentials(user_name, password)
        except (ValueError, TypeError) as e:
            raise fault.BadRequestFault(
                "Cannot parse passwordCredentials", str(e))
Example #15
0
    def from_xml(xml_str):
        try:
            dom = etree.Element("root")
            dom.append(etree.fromstring(xml_str))
            root = dom.find("{http://docs.openstack.org/identity/api/v2.0}" "auth")
            if root is None:
                raise fault.BadRequestFault("Expecting auth")
            token = root.find("{http://docs.openstack.org/identity/api/v2.0}" "token")
            if token is None:
                raise fault.BadRequestFault("Expecting token")

            token_id = token.get("id")
            tenant_id = root.get("tenantId")
            tenant_name = root.get("tenantName")
            utils.check_empty_string(token_id, "Expecting a token id.")
            if tenant_id and tenant_name:
                raise fault.BadRequestFault("Expecting either Tenant ID or Tenant Name, but not both")

            return AuthWithUnscopedToken(token_id, tenant_id, tenant_name)
        except etree.LxmlError as e:
            raise fault.BadRequestFault("Cannot parse password access", str(e))
Example #16
0
    def from_json(json_str):
        try:
            obj = json.loads(json_str)
            if not "user" in obj:
                raise fault.BadRequestFault("Expecting User")
            user = obj["user"]
            id = user.get('id', None)
            name = user.get('name', None)

            if not "password" in user:
                raise fault.BadRequestFault("Expecting User Password")
            password = user["password"]

            if "tenantId" in user:
                tenant_id = user["tenantId"]
            else:
                tenant_id = None
            if "email" not in user:
                raise fault.BadRequestFault("Expecting User Email")
            email = user["email"]
            utils.check_empty_string(name, "Expecting User Name")
            utils.check_empty_string(password, "Expecting User Password")
            utils.check_empty_string(email, "Expecting User email")
            if "enabled" in user:
                set_enabled = user["enabled"]
                if not isinstance(set_enabled, bool):
                    raise fault.BadRequestFault("Bad enabled attribute!")
            else:
                set_enabled = True
            return User(password, id, name, tenant_id, email, set_enabled)
        except (ValueError, TypeError) as e:
            raise fault.BadRequestFault("Cannot parse User", str(e))
Example #17
0
    def from_json(json_str):
        try:
            obj = json.loads(json_str)
            if not "role" in obj:
                raise fault.BadRequestFault("Expecting Role")
            role = obj["role"]

            # Check that fields are valid
            invalid = [key for key in role if key not in\
                       ['id', 'name', 'description', 'serviceId']]
            if invalid != []:
                raise fault.BadRequestFault("Invalid attribute(s): %s" %
                                            invalid)

            id = role.get('id')
            name = role.get('name')
            description = role.get('description')
            service_id = role.get('serviceId')
            utils.check_empty_string(name, "Expecting Role name")
            return Role(id, name, description, service_id)
        except (ValueError, TypeError) as e:
            raise fault.BadRequestFault("Cannot parse Role", str(e))
Example #18
0
    def from_json(json_str):
        try:
            obj = json.loads(json_str)
            if not "role" in obj:
                raise fault.BadRequestFault("Expecting Role")
            role = obj["role"]

            # Check that fields are valid
            invalid = [key for key in role if key not in\
                       ['id', 'name', 'description', 'serviceId']]
            if invalid != []:
                raise fault.BadRequestFault("Invalid attribute(s): %s"
                                            % invalid)

            id = role.get('id')
            name = role.get('name')
            description = role.get('description')
            service_id = role.get('serviceId')
            utils.check_empty_string(name, "Expecting Role name")
            return Role(id, name, description, service_id)
        except (ValueError, TypeError) as e:
            raise fault.BadRequestFault("Cannot parse Role", str(e))
Example #19
0
    def from_xml(xml_str):
        try:
            dom = etree.Element("root")
            dom.append(etree.fromstring(xml_str))
            root = dom.find("{http://docs.openstack.org/identity/api/v2.0}"
                            "auth")
            if root is None:
                raise fault.BadRequestFault("Expecting auth")
            token = root.find("{http://docs.openstack.org/identity/api/v2.0}"
                              "token")
            if token is None:
                raise fault.BadRequestFault("Expecting token")

            token_id = token.get("id")
            tenant_id = root.get("tenantId")
            tenant_name = root.get("tenantName")
            utils.check_empty_string(token_id, "Expecting a token id.")
            if tenant_id and tenant_name:
                raise fault.BadRequestFault(
                    "Expecting either Tenant ID or Tenant Name, but not both")

            return AuthWithUnscopedToken(token_id, tenant_id, tenant_name)
        except etree.LxmlError as e:
            raise fault.BadRequestFault("Cannot parse password access", str(e))
Example #20
0
    def from_json(json_str):
        try:
            obj = json.loads(json_str)
            if not "user" in obj:
                raise fault.BadRequestFault("Expecting User")
            user = obj["user"]

            # Check that fields are valid
            invalid = [
                key for key in user if key not in
                ['id', 'name', 'password', 'tenantId', 'email', 'enabled']
            ]
            if invalid != []:
                raise fault.BadRequestFault("Invalid attribute(s): %s" %
                                            invalid)

            id = user.get('id', None)
            name = user.get('name', None)

            if not "password" in user:
                raise fault.BadRequestFault("Expecting User Password")
            password = user["password"]

            if "tenantId" in user:
                tenant_id = user["tenantId"]
            else:
                tenant_id = None
            if "email" not in user:
                raise fault.BadRequestFault("Expecting User Email")
            email = user["email"]
            utils.check_empty_string(name, "Expecting User Name")
            utils.check_empty_string(password, "Expecting User Password")
            utils.check_empty_string(email, "Expecting User email")
            if "enabled" in user:
                set_enabled = user["enabled"]
                if not isinstance(set_enabled, bool):
                    raise fault.BadRequestFault("Bad enabled attribute!")
            else:
                set_enabled = True
            return User(password, id, name, tenant_id, email, set_enabled)
        except (ValueError, TypeError) as e:
            raise fault.BadRequestFault("Cannot parse User", str(e))
Example #21
0
    def from_xml(xml_str):
        try:
            dom = etree.Element("root")
            dom.append(etree.fromstring(xml_str))
            root = dom.find("{http://docs.openstack.org/identity/api/v2.0}" \
                            "user")
            if root is None:
                raise fault.BadRequestFault("Expecting User")
            name = root.get("name")
            tenant_id = root.get("tenantId")
            email = root.get("email")
            password = root.get("password")
            enabled = root.get("enabled")
            utils.check_empty_string(name, "Expecting User Name")
            utils.check_empty_string(password, "Expecting User Password")
            utils.check_empty_string(email, "Expecting User email")
            enabled = enabled is None or enabled.lower() in ["true", "yes"]

            return User(password, id, name, tenant_id, email, enabled)
        except etree.LxmlError as e:
            raise fault.BadRequestFault("Cannot parse User", str(e))
Example #22
0
    def from_xml(xml_str):
        try:
            dom = etree.Element("root")
            dom.append(etree.fromstring(xml_str))
            root = dom.find("{http://docs.openstack.org/identity/api/v2.0}" \
                            "user")
            if root is None:
                raise fault.BadRequestFault("Expecting User")

            name = root.get("name")
            tenant_id = root.get("tenantId")
            email = root.get("email")
            password = root.get("password")
            enabled = root.get("enabled")
            utils.check_empty_string(name, "Expecting User Name")
            utils.check_empty_string(password, "Expecting User Password")
            utils.check_empty_string(email, "Expecting User email")
            enabled = enabled is None or enabled.lower() in ["true", "yes"]

            return User(password, id, name, tenant_id, email, enabled)
        except etree.LxmlError as e:
            raise fault.BadRequestFault("Cannot parse User", str(e))