Change V3 extensions to use resources

The V3 extension classes are changed to use the resource-oriented
method to map paths.

bp json-home

Change-Id: I4286f0affee7570b509c215f3375b2a517a5af4f
This commit is contained in:
Brant Knudson 2014-08-02 18:11:55 -05:00
parent d84dbec3e8
commit 1599aff511
8 changed files with 139 additions and 244 deletions

View File

@ -54,30 +54,19 @@ class Ec2ExtensionV3(wsgi.V3ExtensionRouter):
def add_routes(self, mapper):
ec2_controller = controllers.Ec2ControllerV3()
# validation
mapper.connect(
'/ec2tokens',
controller=ec2_controller,
action='authenticate',
conditions=dict(method=['POST']))
self._add_resource(
mapper, ec2_controller,
path='/ec2tokens',
post_action='authenticate')
# crud
mapper.connect(
'/users/{user_id}/credentials/OS-EC2',
controller=ec2_controller,
action='ec2_create_credential',
conditions=dict(method=['POST']))
mapper.connect(
'/users/{user_id}/credentials/OS-EC2',
controller=ec2_controller,
action='ec2_list_credentials',
conditions=dict(method=['GET']))
mapper.connect(
'/users/{user_id}/credentials/OS-EC2/{credential_id}',
controller=ec2_controller,
action='ec2_get_credential',
conditions=dict(method=['GET']))
mapper.connect(
'/users/{user_id}/credentials/OS-EC2/{credential_id}',
controller=ec2_controller,
action='ec2_delete_credential',
conditions=dict(method=['DELETE']))
self._add_resource(
mapper, ec2_controller,
path='/users/{user_id}/credentials/OS-EC2',
get_action='ec2_list_credentials',
post_action='ec2_create_credential')
self._add_resource(
mapper, ec2_controller,
path='/users/{user_id}/credentials/OS-EC2/{credential_id}',
get_action='ec2_get_credential',
delete_action='ec2_delete_credential')

View File

@ -23,23 +23,18 @@ class EndpointFilterExtension(wsgi.V3ExtensionRouter):
def add_routes(self, mapper):
endpoint_filter_controller = controllers.EndpointFilterV3Controller()
mapper.connect(self.PATH_PREFIX + '/endpoints/{endpoint_id}/projects',
controller=endpoint_filter_controller,
action='list_projects_for_endpoint',
conditions=dict(method=['GET']))
mapper.connect(self.PATH_PREFIX + self.PATH_PROJECT_ENDPOINT,
controller=endpoint_filter_controller,
action='add_endpoint_to_project',
conditions=dict(method=['PUT']))
mapper.connect(self.PATH_PREFIX + self.PATH_PROJECT_ENDPOINT,
controller=endpoint_filter_controller,
action='check_endpoint_in_project',
conditions=dict(method=['GET', 'HEAD']))
mapper.connect(self.PATH_PREFIX + '/projects/{project_id}/endpoints',
controller=endpoint_filter_controller,
action='list_endpoints_for_project',
conditions=dict(method=['GET']))
mapper.connect(self.PATH_PREFIX + self.PATH_PROJECT_ENDPOINT,
controller=endpoint_filter_controller,
action='remove_endpoint_from_project',
conditions=dict(method=['DELETE']))
self._add_resource(
mapper, endpoint_filter_controller,
path=self.PATH_PREFIX + '/endpoints/{endpoint_id}/projects',
get_action='list_projects_for_endpoint')
self._add_resource(
mapper, endpoint_filter_controller,
path=self.PATH_PREFIX + self.PATH_PROJECT_ENDPOINT,
get_head_action='check_endpoint_in_project',
put_action='add_endpoint_to_project',
delete_action='remove_endpoint_from_project')
self._add_resource(
mapper, endpoint_filter_controller,
path=self.PATH_PREFIX + '/projects/{project_id}/endpoints',
get_action='list_endpoints_for_project')

View File

@ -22,7 +22,8 @@ class ExampleRouter(wsgi.V3ExtensionRouter):
def add_routes(self, mapper):
example_controller = controllers.ExampleV3Controller()
mapper.connect(self.PATH_PREFIX + '/example',
controller=example_controller,
action='do_something',
conditions=dict(method=['GET']))
self._add_resource(
mapper, example_controller,
path=self.PATH_PREFIX + '/example',
get_action='do_something')

View File

@ -76,121 +76,56 @@ class FederationExtension(_BaseFederationExtension):
# Identity Provider CRUD operations
mapper.connect(
self._construct_url('identity_providers/{idp_id}'),
controller=idp_controller,
action='create_identity_provider',
conditions=dict(method=['PUT']))
mapper.connect(
self._construct_url('identity_providers'),
controller=idp_controller,
action='list_identity_providers',
conditions=dict(method=['GET']))
mapper.connect(
self._construct_url('identity_providers/{idp_id}'),
controller=idp_controller,
action='get_identity_provider',
conditions=dict(method=['GET']))
mapper.connect(
self._construct_url('identity_providers/{idp_id}'),
controller=idp_controller,
action='delete_identity_provider',
conditions=dict(method=['DELETE']))
mapper.connect(
self._construct_url('identity_providers/{idp_id}'),
controller=idp_controller,
action='update_identity_provider',
conditions=dict(method=['PATCH']))
self._add_resource(
mapper, idp_controller,
path=self._construct_url('identity_providers/{idp_id}'),
get_action='get_identity_provider',
put_action='create_identity_provider',
patch_action='update_identity_provider',
delete_action='delete_identity_provider')
self._add_resource(
mapper, idp_controller,
path=self._construct_url('identity_providers'),
get_action='list_identity_providers')
# Protocol CRUD operations
mapper.connect(
self._construct_url('identity_providers/{idp_id}/'
'protocols/{protocol_id}'),
controller=protocol_controller,
action='create_protocol',
conditions=dict(method=['PUT']))
mapper.connect(
self._construct_url('identity_providers/{idp_id}/'
'protocols/{protocol_id}'),
controller=protocol_controller,
action='update_protocol',
conditions=dict(method=['PATCH']))
mapper.connect(
self._construct_url('identity_providers/{idp_id}/'
'protocols/{protocol_id}'),
controller=protocol_controller,
action='get_protocol',
conditions=dict(method=['GET']))
mapper.connect(
self._construct_url('identity_providers/{idp_id}/'
'protocols'),
controller=protocol_controller,
action='list_protocols',
conditions=dict(method=['GET']))
mapper.connect(
self._construct_url('identity_providers/{idp_id}/'
'protocols/{protocol_id}'),
controller=protocol_controller,
action='delete_protocol',
conditions=dict(method=['DELETE']))
self._add_resource(
mapper, protocol_controller,
path=self._construct_url('identity_providers/{idp_id}/protocols/'
'{protocol_id}'),
get_action='get_protocol',
put_action='create_protocol',
patch_action='update_protocol',
delete_action='delete_protocol')
self._add_resource(
mapper, protocol_controller,
path=self._construct_url('identity_providers/{idp_id}/protocols'),
get_action='list_protocols')
# Mapping CRUD operations
mapper.connect(
self._construct_url('mappings/{mapping_id}'),
controller=mapping_controller,
action='create_mapping',
conditions=dict(method=['PUT']))
mapper.connect(
self._construct_url('mappings'),
controller=mapping_controller,
action='list_mappings',
conditions=dict(method=['GET']))
mapper.connect(
self._construct_url('mappings/{mapping_id}'),
controller=mapping_controller,
action='get_mapping',
conditions=dict(method=['GET']))
mapper.connect(
self._construct_url('mappings/{mapping_id}'),
controller=mapping_controller,
action='delete_mapping',
conditions=dict(method=['DELETE']))
mapper.connect(
self._construct_url('mappings/{mapping_id}'),
controller=mapping_controller,
action='update_mapping',
conditions=dict(method=['PATCH']))
mapper.connect(
self._construct_url('domains'),
controller=domain_controller,
action='list_domains_for_groups',
conditions=dict(method=['GET']))
mapper.connect(
self._construct_url('projects'),
controller=project_controller,
action='list_projects_for_groups',
conditions=dict(method=['GET']))
mapper.connect(
self._construct_url('identity_providers/'
'{identity_provider}/protocols/'
'{protocol}/auth'),
controller=auth_controller,
action='federated_authentication',
conditions=dict(method=['GET', 'POST']))
self._add_resource(
mapper, mapping_controller,
path=self._construct_url('mappings/{mapping_id}'),
get_action='get_mapping',
put_action='create_mapping',
patch_action='update_mapping',
delete_action='delete_mapping')
self._add_resource(
mapper, mapping_controller,
path=self._construct_url('mappings'),
get_action='list_mappings')
self._add_resource(
mapper, domain_controller,
path=self._construct_url('domains'),
get_action='list_domains_for_groups')
self._add_resource(
mapper, project_controller,
path=self._construct_url('projects'),
get_action='list_projects_for_groups')
self._add_resource(
mapper, auth_controller,
path=self._construct_url('identity_providers/{identity_provider}/'
'protocols/{protocol}/auth'),
get_post_action='federated_authentication')

View File

@ -59,73 +59,49 @@ class OAuth1Extension(wsgi.V3ExtensionRouter):
oauth_controller = controllers.OAuthControllerV3()
# basic admin-only consumer crud
mapper.connect(
'/OS-OAUTH1/consumers',
controller=consumer_controller,
action='create_consumer',
conditions=dict(method=['POST']))
mapper.connect(
'/OS-OAUTH1/consumers/{consumer_id}',
controller=consumer_controller,
action='get_consumer',
conditions=dict(method=['GET']))
mapper.connect(
'/OS-OAUTH1/consumers/{consumer_id}',
controller=consumer_controller,
action='update_consumer',
conditions=dict(method=['PATCH']))
mapper.connect(
'/OS-OAUTH1/consumers/{consumer_id}',
controller=consumer_controller,
action='delete_consumer',
conditions=dict(method=['DELETE']))
mapper.connect(
'/OS-OAUTH1/consumers',
controller=consumer_controller,
action='list_consumers',
conditions=dict(method=['GET']))
self._add_resource(
mapper, consumer_controller,
path='/OS-OAUTH1/consumers',
get_action='list_consumers',
post_action='create_consumer')
self._add_resource(
mapper, consumer_controller,
path='/OS-OAUTH1/consumers/{consumer_id}',
get_action='get_consumer',
patch_action='update_consumer',
delete_action='delete_consumer')
# user accesss token crud
mapper.connect(
'/users/{user_id}/OS-OAUTH1/access_tokens',
controller=access_token_controller,
action='list_access_tokens',
conditions=dict(method=['GET']))
mapper.connect(
'/users/{user_id}/OS-OAUTH1/access_tokens/{access_token_id}',
controller=access_token_controller,
action='get_access_token',
conditions=dict(method=['GET']))
mapper.connect(
'/users/{user_id}/OS-OAUTH1/access_tokens/{access_token_id}',
controller=access_token_controller,
action='delete_access_token',
conditions=dict(method=['DELETE']))
mapper.connect(
'/users/{user_id}/OS-OAUTH1/access_tokens/{access_token_id}/roles',
controller=access_token_roles_controller,
action='list_access_token_roles',
conditions=dict(method=['GET']))
mapper.connect(
'/users/{user_id}/OS-OAUTH1/access_tokens/'
'{access_token_id}/roles/{role_id}',
controller=access_token_roles_controller,
action='get_access_token_role',
conditions=dict(method=['GET']))
self._add_resource(
mapper, access_token_controller,
path='/users/{user_id}/OS-OAUTH1/access_tokens',
get_action='list_access_tokens')
self._add_resource(
mapper, access_token_controller,
path='/users/{user_id}/OS-OAUTH1/access_tokens/{access_token_id}',
get_action='get_access_token',
delete_action='delete_access_token')
self._add_resource(
mapper, access_token_roles_controller,
path='/users/{user_id}/OS-OAUTH1/access_tokens/{access_token_id}/'
'roles',
get_action='list_access_token_roles')
self._add_resource(
mapper, access_token_roles_controller,
path='/users/{user_id}/OS-OAUTH1/access_tokens/{access_token_id}/'
'roles/{role_id}',
get_action='get_access_token_role')
# oauth flow calls
mapper.connect(
'/OS-OAUTH1/request_token',
controller=oauth_controller,
action='create_request_token',
conditions=dict(method=['POST']))
mapper.connect(
'/OS-OAUTH1/access_token',
controller=oauth_controller,
action='create_access_token',
conditions=dict(method=['POST']))
mapper.connect(
'/OS-OAUTH1/authorize/{request_token_id}',
controller=oauth_controller,
action='authorize_request_token',
conditions=dict(method=['PUT']))
self._add_resource(
mapper, oauth_controller,
path='/OS-OAUTH1/request_token',
post_action='create_request_token')
self._add_resource(
mapper, oauth_controller,
path='/OS-OAUTH1/access_token',
post_action='create_access_token')
self._add_resource(
mapper, oauth_controller,
path='/OS-OAUTH1/authorize/{request_token_id}',
put_action='authorize_request_token')

View File

@ -20,7 +20,7 @@ class RevokeExtension(wsgi.V3ExtensionRouter):
def add_routes(self, mapper):
revoke_controller = controllers.RevokeController()
mapper.connect(self.PATH_PREFIX + '/events',
controller=revoke_controller,
action='list_revoke_events',
conditions=dict(method=['GET']))
self._add_resource(
mapper, revoke_controller,
path=self.PATH_PREFIX + '/events',
get_action='list_revoke_events')

View File

@ -56,10 +56,10 @@ class S3Extension(wsgi.V3ExtensionRouter):
def add_routes(self, mapper):
controller = S3Controller()
# validation
mapper.connect('/s3tokens',
controller=controller,
action='authenticate',
conditions=dict(method=['POST']))
self._add_resource(
mapper, controller,
path='/s3tokens',
post_action='authenticate')
class S3Controller(controllers.Ec2Controller):

View File

@ -21,12 +21,11 @@ class SimpleCertExtension(wsgi.V3ExtensionRouter):
def add_routes(self, mapper):
controller = controllers.SimpleCert()
mapper.connect('/%s/ca' % self.PREFIX,
controller=controller,
action='get_ca_certificate',
conditions=dict(method=['GET']))
mapper.connect('/%s/certificates' % self.PREFIX,
controller=controller,
action='list_certificates',
conditions=dict(method=['GET']))
self._add_resource(
mapper, controller,
path='/%s/ca' % self.PREFIX,
get_action='get_ca_certificate')
self._add_resource(
mapper, controller,
path='/%s/certificates' % self.PREFIX,
get_action='list_certificates')