def __call__(self, env, start_response): # Inspect the request for mime type and API version env = normalize_accept_header(env) env = normalize_path_prefix(env) env = normalize_path_suffix(env) env['PATH_INFO'] = normalize_starting_slash(env.get('PATH_INFO')) env['PATH_INFO'] = normalize_trailing_slash(env['PATH_INFO']) # Fall back on defaults, if necessary env['KEYSTONE_RESPONSE_ENCODING'] = env.get( 'KEYSTONE_RESPONSE_ENCODING') or DEFAULT_RESPONSE_ENCODING env['HTTP_ACCEPT'] = 'application/' + ( env.get('KEYSTONE_RESPONSE_ENCODING') or DEFAULT_RESPONSE_ENCODING) if 'KEYSTONE_API_VERSION' not in env: # Version was not specified in path or headers # return multiple choice unless the version controller can handle # this request if env['PATH_INFO'] not in ['/', '']: from keystone.controllers.version import VersionController controller = VersionController(options=None) response = controller.get_multiple_choice( req=Request(env), file='multiple_choice') return response(env, start_response) return self.app(env, start_response)
def __call__(self, env, start_response): # Inspect the request for mime type and API version env = normalize_accept_header(env) env = normalize_path_prefix(env) env = normalize_path_suffix(env) env['PATH_INFO'] = normalize_starting_slash(env.get('PATH_INFO')) env['PATH_INFO'] = normalize_trailing_slash(env['PATH_INFO']) # Fall back on defaults, if necessary env['KEYSTONE_RESPONSE_ENCODING'] = env.get( 'KEYSTONE_RESPONSE_ENCODING') or DEFAULT_RESPONSE_ENCODING env['HTTP_ACCEPT'] = 'application/' + (env.get( 'KEYSTONE_RESPONSE_ENCODING') or DEFAULT_RESPONSE_ENCODING) if 'KEYSTONE_API_VERSION' not in env: # Version was not specified in path or headers # return multiple choice unless the version controller can handle # this request if env['PATH_INFO'] not in ['/', '']: logger.debug("Call without a version - returning 300. Path=%s" % env.get('PATH_INFO', '')) from keystone.controllers.version import VersionController controller = VersionController(options=None) response = controller.get_multiple_choice(req=Request(env), file='multiple_choice') return response(env, start_response) return self.app(env, start_response)
def __call__(self, env, start_response): # Inspect the request for mime type and API version env = normalize_accept_header(env) env = normalize_path_prefix(env) env = normalize_path_suffix(env) env["PATH_INFO"] = normalize_starting_slash(env.get("PATH_INFO")) env["PATH_INFO"] = normalize_trailing_slash(env["PATH_INFO"]) # Fall back on defaults, if necessary env["KEYSTONE_RESPONSE_ENCODING"] = env.get("KEYSTONE_RESPONSE_ENCODING") or DEFAULT_RESPONSE_ENCODING env["HTTP_ACCEPT"] = "application/" + (env.get("KEYSTONE_RESPONSE_ENCODING") or DEFAULT_RESPONSE_ENCODING) if "KEYSTONE_API_VERSION" not in env: # Version was not specified in path or headers # return multiple choice unless the version controller can handle # this request if env["PATH_INFO"] not in ["/", ""]: from keystone.controllers.version import VersionController controller = VersionController(options=None) response = controller.get_multiple_choice(req=Request(env), file="multiple_choice") return response(env, start_response) return self.app(env, start_response)
def __init__(self, options): self.options = options mapper = routes.Mapper() db.configure_backends(options) # Token Operations auth_controller = AuthController(options) mapper.connect("/tokens", controller=auth_controller, action="authenticate", conditions=dict(method=["POST"])) mapper.connect("/tokens/{token_id}", controller=auth_controller, action="validate_token", conditions=dict(method=["GET"])) mapper.connect("/tokens/{token_id}", controller=auth_controller, action="check_token", conditions=dict(method=["HEAD"])) # Do we need this.API doesn't have delete token. mapper.connect("/tokens/{token_id}", controller=auth_controller, action="delete_token", conditions=dict(method=["DELETE"])) mapper.connect("/tokens/{token_id}/endpoints", controller=auth_controller, action="endpoints", conditions=dict(method=["GET"])) # Tenant Operations tenant_controller = TenantController(options) mapper.connect("/tenants", controller=tenant_controller, action="get_tenants", conditions=dict(method=["GET"])) mapper.connect("/tenants/{tenant_id}", controller=tenant_controller, action="get_tenant", conditions=dict(method=["GET"])) roles_controller = RolesController(options) mapper.connect("/tenants/{tenant_id}/users/{user_id}/roles", controller=roles_controller, action="get_user_roles", conditions=dict(method=["GET"])) # User Operations user_controller = UserController(options) mapper.connect("/users/{user_id}", controller=user_controller, action="get_user", conditions=dict(method=["GET"])) mapper.connect("/users/{user_id}/roles", controller=roles_controller, action="get_user_roles", conditions=dict(method=["GET"])) # Miscellaneous Operations version_controller = VersionController(options) mapper.connect("/", controller=version_controller, action="get_version_info", file="admin/version", conditions=dict(method=["GET"])) extensions_controller = ExtensionsController(options) mapper.connect("/extensions", controller=extensions_controller, action="get_extensions_info", path="content/admin/extensions", conditions=dict(method=["GET"])) # Static Files Controller static_files_controller = StaticFilesController(options) mapper.connect("/identityadminguide.pdf", controller=static_files_controller, action="get_pdf_contract", root="content/admin/", pdf="identityadminguide.pdf", conditions=dict(method=["GET"])) mapper.connect("/identity-admin.wadl", controller=static_files_controller, action="get_wadl_contract", root="content/admin/", wadl="identity-admin.wadl", conditions=dict(method=["GET"])) mapper.connect("/common.ent", controller=static_files_controller, action="get_wadl_contract", root="content/common/", wadl="common.ent", conditions=dict(method=["GET"])) mapper.connect("/xsd/{xsd}", controller=static_files_controller, action="get_xsd_contract", root="content/common/", conditions=dict(method=["GET"])) mapper.connect("/xsd/atom/{xsd}", controller=static_files_controller, action="get_xsd_atom_contract", root="content/common/", conditions=dict(method=["GET"])) mapper.connect("/xslt/{file:.*}", controller=static_files_controller, action="get_static_file", root="content/common/", path="xslt/", mimetype="application/xml", conditions=dict(method=["GET"])) mapper.connect("/js/{file:.*}", controller=static_files_controller, action="get_static_file", root="content/common/", path="js/", mimetype="application/javascript", conditions=dict(method=["GET"])) mapper.connect("/style/{file:.*}", controller=static_files_controller, action="get_static_file", root="content/common/", path="style/", mimetype="application/css", conditions=dict(method=["GET"])) mapper.connect("/samples/{file:.*}", controller=static_files_controller, action="get_static_file", root="content/common/", path="samples/", conditions=dict(method=["GET"])) extension.configure_extensions(mapper, options) super(AdminApi, self).__init__(mapper)
def __init__(self, options): self.options = options mapper = routes.Mapper() db.configure_backends(options) # Token Operations auth_controller = AuthController(options) mapper.connect("/tokens", controller=auth_controller, action="authenticate", conditions=dict(method=["POST"])) mapper.connect("/tokens/{token_id}", controller=auth_controller, action="validate_token", conditions=dict(method=["GET"])) mapper.connect("/tokens/{token_id}", controller=auth_controller, action="check_token", conditions=dict(method=["HEAD"])) mapper.connect("/tokens/{token_id}", controller=auth_controller, action="delete_token", conditions=dict(method=["DELETE"])) mapper.connect("/tokens/{token_id}/endpoints", controller=auth_controller, action="endpoints", conditions=dict(method=["GET"])) # Tenant Operations tenant_controller = TenantController(options) mapper.connect("/tenants", controller=tenant_controller, action="create_tenant", conditions=dict(method=["POST"])) mapper.connect("/tenants", controller=tenant_controller, action="get_tenants", conditions=dict(method=["GET"])) mapper.connect("/tenants/{tenant_id}", controller=tenant_controller, action="update_tenant", conditions=dict(method=["PUT"])) mapper.connect("/tenants/{tenant_id}", controller=tenant_controller, action="get_tenant", conditions=dict(method=["GET"])) mapper.connect("/tenants/{tenant_id}", controller=tenant_controller, action="delete_tenant", conditions=dict(method=["DELETE"])) # User Operations user_controller = UserController(options) mapper.connect("/users", controller=user_controller, action="create_user", conditions=dict(method=["POST"])) mapper.connect("/users", controller=user_controller, action="get_users", conditions=dict(method=["GET"])) mapper.connect("/users/{user_id}", controller=user_controller, action="get_user", conditions=dict(method=["GET"])) mapper.connect("/users/{user_id}", controller=user_controller, action="update_user", conditions=dict(method=["PUT"])) mapper.connect("/users/{user_id}", controller=user_controller, action="delete_user", conditions=dict(method=["DELETE"])) mapper.connect("/users/{user_id}/eppn", controller=user_controller, action="set_user_eppn", conditions=dict(method=["PUT"])) mapper.connect("/users/{user_id}/password", controller=user_controller, action="set_user_password", conditions=dict(method=["PUT"])) mapper.connect("/users/{user_id}/tenant", controller=user_controller, action="update_user_tenant", conditions=dict(method=["PUT"])) # Test this, test failed mapper.connect("/users/{user_id}/enabled", controller=user_controller, action="set_user_enabled", conditions=dict(method=["PUT"])) mapper.connect("/tenants/{tenant_id}/users", controller=user_controller, action="get_tenant_users", conditions=dict(method=["GET"])) """ get token by email add by colony. """ # Get token by key Operations token_by_controller = TokenByController(options) mapper.connect("/token_by/email", controller=token_by_controller, action="get_token_by", conditions=dict(method=["POST"])) mapper.connect("/token_by/eppn", controller=token_by_controller, action="get_token_by", conditions=dict(method=["POST"])) #EndpointTemplatesControllers and Endpoints endpoint_templates_controller = EndpointTemplatesController(options) mapper.connect("/endpointTemplates", controller=endpoint_templates_controller, action="get_endpoint_templates", conditions=dict(method=["GET"])) mapper.connect("/endpointTemplates", controller=endpoint_templates_controller, action="add_endpoint_template", conditions=dict(method=["POST"])) mapper.connect("/endpointTemplates/{endpoint_template_id}", controller=endpoint_templates_controller, action="get_endpoint_template", conditions=dict(method=["GET"])) mapper.connect("/endpointTemplates/{endpoint_template_id}", controller=endpoint_templates_controller, action="modify_endpoint_template", conditions=dict(method=["PUT"])) mapper.connect("/endpointTemplates/{endpoint_template_id}", controller=endpoint_templates_controller, action="delete_endpoint_template", conditions=dict(method=["DELETE"])) mapper.connect("/tenants/{tenant_id}/endpoints", controller=endpoint_templates_controller, action="get_endpoints_for_tenant", conditions=dict(method=["GET"])) mapper.connect("/tenants/{tenant_id}/endpoints", controller=endpoint_templates_controller, action="add_endpoint_to_tenant", conditions=dict(method=["POST"])) mapper.connect( "/tenants/{tenant_id}/endpoints/{endpoint_id}", controller=endpoint_templates_controller, action="remove_endpoint_from_tenant", conditions=dict(method=["DELETE"])) # Miscellaneous Operations version_controller = VersionController(options) mapper.connect("/", controller=version_controller, action="get_version_info", file="admin/version", conditions=dict(method=["GET"])) extensions_controller = ExtensionsController(options) mapper.connect("/extensions", controller=extensions_controller, action="get_extensions_info", path="content/admin/extensions", conditions=dict(method=["GET"])) # Static Files Controller static_files_controller = StaticFilesController(options) mapper.connect("/identityadminguide.pdf", controller=static_files_controller, action="get_pdf_contract", root="content/admin/", pdf="identityadminguide.pdf", conditions=dict(method=["GET"])) mapper.connect("/identity-admin.wadl", controller=static_files_controller, action="get_wadl_contract", root="content/admin/", wadl="identity-admin.wadl", conditions=dict(method=["GET"])) mapper.connect("/common.ent", controller=static_files_controller, action="get_wadl_contract", root="content/common/", wadl="common.ent", conditions=dict(method=["GET"])) mapper.connect("/xsd/{xsd}", controller=static_files_controller, action="get_xsd_contract", root="content/common/", conditions=dict(method=["GET"])) mapper.connect("/xsd/atom/{xsd}", controller=static_files_controller, action="get_xsd_atom_contract", root="content/common/", conditions=dict(method=["GET"])) mapper.connect("/xslt/{file:.*}", controller=static_files_controller, action="get_static_file", root="content/common/", path="xslt/", mimetype="application/xml", conditions=dict(method=["GET"])) mapper.connect("/js/{file:.*}", controller=static_files_controller, action="get_static_file", root="content/common/", path="js/", mimetype="application/javascript", conditions=dict(method=["GET"])) mapper.connect("/style/{file:.*}", controller=static_files_controller, action="get_static_file", root="content/common/", path="style/", mimetype="application/css", conditions=dict(method=["GET"])) mapper.connect("/samples/{file:.*}", controller=static_files_controller, action="get_static_file", root="content/common/", path="samples/", conditions=dict(method=["GET"])) extension.configure_extensions(mapper, options) super(AdminApi, self).__init__(mapper)
def setUp(self): self.controller = VersionController({})
class TestVersionController(unittest.TestCase): def setUp(self): self.controller = VersionController({}) def _default_version(self, file=None): """ Verify default response for versions is JSON """ if file is None: file = 'admin/version' req = Request.blank('/') req.environ = {} response = self.controller.get_version_info(req, file=file) self.assertEqual(response.content_type, 'application/json') data = json.loads(response.body) self.assertIsNotNone(data) def _json_version(self, file=None): """ Verify JSON response for versions Checks that JSON is returned when Accept is set to application/json. Also checks that verions and version exist and that values are as expected """ if file is None: file = 'admin/version' req = Request.blank('/') req.headers['Accept'] = 'application/json' req.environ = {} response = self.controller.get_version_info(req, file=file) self.assertEqual(response.content_type, 'application/json') data = json.loads(response.body) self.assertIn("versions", data) versions = data['versions'] self.assertIn("values", versions) values = versions['values'] self.assertIsInstance(values, type([])) for version in values: for item in version: self.assertIn(item, ["id", "status", "updated", "links", "media-types"]) def _xml_version(self, file=None): """ Verify XML response for versions Checks that XML is returned when Accept is set to application/xml. Also checks that verions and version tags exist and that attributes are as expected """ if file is None: file = 'admin/version' req = Request.blank('/') req.headers['Accept'] = 'application/xml' req.environ = {} response = self.controller.get_version_info(req, file=file) self.assertEqual(response.content_type, 'application/xml') data = etree.fromstring(response.body) self.assertEqual(data.tag, '{http://docs.openstack.org/common/api/v2.0}versions') for version in data: self.assertEqual(version.tag, '{http://docs.openstack.org/common/api/v2.0}version') for attribute in version.attrib: self.assertIn(attribute, ["id", "status", "updated", "links", "media-types"]) def _atom_version(self, file=None): """ Verify ATOM response for versions Checks that ATOM XML is returned when Accept is set to aapplication/atom+xml. Also checks that verions and version tags exist and that attributes are as expected """ if file is None: file = 'admin/version' req = Request.blank('/') req.headers['Accept'] = 'application/atom+xml' req.environ = {} response = self.controller.get_version_info(req, file=file) self.assertEqual(response.content_type, 'application/atom+xml') data = etree.fromstring(response.body) self.assertEqual(data.tag, '{http://www.w3.org/2005/Atom}feed') def test_default_version_admin(self): self._default_version(file='admin/version') def test_default_version_service(self): self._default_version(file='service/version') def test_xml_version_admin(self): self._xml_version(file='admin/version') def test_xml_version_service(self): self._xml_version(file='service/version') def test_json_version_admin(self): self._json_version(file='admin/version') def test_json_version_service(self): self._json_version(file='service/version') def test_atom_version_admin(self): self._atom_version(file='admin/version') def test_atom_version_service(self): self._atom_version(file='service/version')
def __init__(self): mapper = routes.Mapper() # Token Operations auth_controller = TokenController() mapper.connect("/tokens", controller=auth_controller, action="authenticate", conditions=dict(method=["POST"])) # TODO(zns): this should be deprecated mapper.connect("/ec2tokens", controller=auth_controller, action="authenticate_ec2", conditions=dict(method=["POST"])) tenant_controller = TenantController(True) mapper.connect("/tenants", controller=tenant_controller, action="get_tenants", conditions=dict(method=["GET"])) # Miscellaneous Operations version_controller = VersionController() mapper.connect("/", controller=version_controller, action="get_version_info", file="service/version", conditions=dict(method=["GET"])) extensions_controller = ExtensionsController(True) mapper.connect("/extensions", controller=extensions_controller, action="get_extensions_info", conditions=dict(method=["GET"])) # Static Files Controller static_files_controller = StaticFilesController() mapper.connect("/identitydevguide.pdf", controller=static_files_controller, action="get_pdf_contract", root="content/service/", pdf="identitydevguide.pdf", conditions=dict(method=["GET"])) mapper.connect("/identity.wadl", controller=static_files_controller, action="get_wadl_contract", root="content/service/", wadl="identity.wadl", conditions=dict(method=["GET"])) mapper.connect("/common.ent", controller=static_files_controller, action="get_wadl_contract", wadl="common.ent", root="content/common/", conditions=dict(method=["GET"])) mapper.connect("/xslt/{file:.*}", controller=static_files_controller, action="get_static_file", path="common/xslt/", mimetype="application/xml", conditions=dict(method=["GET"])) mapper.connect("/style/{file:.*}", controller=static_files_controller, action="get_static_file", path="common/style/", mimetype="application/css", conditions=dict(method=["GET"])) mapper.connect("/js/{file:.*}", controller=static_files_controller, action="get_static_file", path="common/js/", mimetype="application/javascript", conditions=dict(method=["GET"])) mapper.connect("/samples/{file:.*}", controller=static_files_controller, action="get_static_file", path="common/samples/", conditions=dict(method=["GET"])) mapper.connect("/xsd/{xsd:.*}", controller=static_files_controller, action="get_xsd_contract", root="content/common/", conditions=dict(method=["GET"])) mapper.connect("/xsd/atom/{xsd}", controller=static_files_controller, action="get_xsd_atom_contract", root="content/common/", conditions=dict(method=["GET"])) mapper.connect("/xsd/atom/{xsd}", controller=static_files_controller, action="get_xsd_atom_contract", root="content/common/", conditions=dict(method=["GET"])) super(ServiceApi, self).__init__(mapper)
class TestVersionController(unittest.TestCase): def setUp(self): self.controller = VersionController({}) def _default_version(self, file=None): """ Verify default response for versions is JSON """ if file is None: file = 'admin/version' req = Request.blank('/') req.environ = {} response = self.controller.get_version_info(req, file=file) self.assertEqual(response.content_type, 'application/json') data = json.loads(response.body) self.assertIsNotNone(data) def _json_version(self, file=None): """ Verify JSON response for versions Checks that JSON is returned when Accept is set to application/json. Also checks that verions and version exist and that values are as expected """ if file is None: file = 'admin/version' req = Request.blank('/') req.headers['Accept'] = 'application/json' req.environ = {} response = self.controller.get_version_info(req, file=file) self.assertEqual(response.content_type, 'application/json') data = json.loads(response.body) self.assertIn("versions", data) versions = data['versions'] self.assertIn("values", versions) values = versions['values'] self.assertIsInstance(values, list) for version in values: for item in version: self.assertIn(item, ["id", "status", "updated", "links", "media-types"]) def _xml_version(self, file=None): """ Verify XML response for versions Checks that XML is returned when Accept is set to application/xml. Also checks that verions and version tags exist and that attributes are as expected """ if file is None: file = 'admin/version' req = Request.blank('/') req.headers['Accept'] = 'application/xml' req.environ = {} response = self.controller.get_version_info(req, file=file) self.assertEqual(response.content_type, 'application/xml') data = etree.fromstring(response.body) self.assertEqual(data.tag, '{http://docs.openstack.org/common/api/v2.0}versions') for version in data: self.assertEqual(version.tag, '{http://docs.openstack.org/common/api/v2.0}version') for attribute in version.attrib: self.assertIn(attribute, ["id", "status", "updated", "links", "media-types"]) def _atom_version(self, file=None): """ Verify ATOM response for versions Checks that ATOM XML is returned when Accept is set to aapplication/atom+xml. Also checks that verions and version tags exist and that attributes are as expected """ if file is None: file = 'admin/version' req = Request.blank('/') req.headers['Accept'] = 'application/atom+xml' req.environ = {} response = self.controller.get_version_info(req, file=file) self.assertEqual(response.content_type, 'application/atom+xml') data = etree.fromstring(response.body) self.assertEqual(data.tag, '{http://www.w3.org/2005/Atom}feed') def test_default_version_admin(self): self._default_version(file='admin/version') def test_default_version_service(self): self._default_version(file='service/version') def test_xml_version_admin(self): self._xml_version(file='admin/version') def test_xml_version_service(self): self._xml_version(file='service/version') def test_json_version_admin(self): self._json_version(file='admin/version') def test_json_version_service(self): self._json_version(file='service/version') def test_atom_version_admin(self): self._atom_version(file='admin/version') def test_atom_version_service(self): self._atom_version(file='service/version')
def __init__(self, options): self.options = options mapper = routes.Mapper() db.configure_backends(options) # Token Operations auth_controller = AuthController(options) mapper.connect("/tokens", controller=auth_controller, action="authenticate", conditions=dict(method=["POST"])) mapper.connect("/ec2tokens", controller=auth_controller, action="authenticate_ec2", conditions=dict(method=["POST"])) mapper.connect("/s3tokens", controller=auth_controller, action="authenticate_s3", conditions=dict(method=["POST"])) tenant_controller = TenantController(options, True) mapper.connect("/tenants", controller=tenant_controller, action="get_tenants", conditions=dict(method=["GET"])) user_controller = UserController(options) mapper.connect("/tenants/{tenant_id}/users", controller=user_controller, action="get_tenant_users", conditions=dict(method=["GET"])) # Miscellaneous Operations version_controller = VersionController(options) mapper.connect("/", controller=version_controller, action="get_version_info", file="service/version", conditions=dict(method=["GET"])) extensions_controller = ExtensionsController(options) mapper.connect("/extensions", controller=extensions_controller, action="get_extensions_info", path="content/service/extensions", conditions=dict(method=["GET"])) # Static Files Controller static_files_controller = StaticFilesController(options) mapper.connect("/identitydevguide.pdf", controller=static_files_controller, action="get_pdf_contract", root="content/service/", pdf="identitydevguide.pdf", conditions=dict(method=["GET"])) mapper.connect("/identity.wadl", controller=static_files_controller, action="get_wadl_contract", root="content/service/", wadl="identity.wadl", conditions=dict(method=["GET"])) mapper.connect("/common.ent", controller=static_files_controller, action="get_wadl_contract", wadl="common.ent", root="content/common/", conditions=dict(method=["GET"])) mapper.connect("/xslt/{file:.*}", controller=static_files_controller, action="get_static_file", path="common/xslt/", mimetype="application/xml", conditions=dict(method=["GET"])) mapper.connect("/style/{file:.*}", controller=static_files_controller, action="get_static_file", path="common/style/", mimetype="application/css", conditions=dict(method=["GET"])) mapper.connect("/js/{file:.*}", controller=static_files_controller, action="get_static_file", path="common/js/", mimetype="application/javascript", conditions=dict(method=["GET"])) mapper.connect("/samples/{file:.*}", controller=static_files_controller, action="get_static_file", path="common/samples/", conditions=dict(method=["GET"])) mapper.connect("/xsd/{xsd:.*}", controller=static_files_controller, action="get_xsd_contract", root="content/common/", conditions=dict(method=["GET"])) mapper.connect("/xsd/atom/{xsd}", controller=static_files_controller, action="get_xsd_atom_contract", root="content/common/", conditions=dict(method=["GET"])) mapper.connect("/xsd/atom/{xsd}", controller=static_files_controller, action="get_xsd_atom_contract", root="content/common/", conditions=dict(method=["GET"])) super(ServiceApi, self).__init__(mapper)