예제 #1
0
    def __init__(self, mapper):

        reject_method_resource = wsgi.Resource(wsgi.RejectMethodController())

        search_catalog_resource = search.create_resource()
        mapper.connect('/search',
                       controller=search_catalog_resource,
                       action='search',
                       conditions={'method': ['GET']})
        mapper.connect('/search',
                       controller=search_catalog_resource,
                       action='search',
                       conditions={'method': ['POST']})
        mapper.connect(
            '/search',
            controller=reject_method_resource,
            action='reject',
            allowed_methods='GET, POST',
            conditions={'method': ['PUT', 'DELETE', 'PATCH', 'HEAD']})

        mapper.connect('/index',
                       controller=search_catalog_resource,
                       action='index',
                       conditions={'method': ['POST']})
        mapper.connect(
            '/index',
            controller=reject_method_resource,
            action='reject',
            allowed_methods='POST',
            conditions={'method': ['GET', 'PUT', 'DELETE', 'PATCH', 'HEAD']})

        super(API, self).__init__(mapper)
예제 #2
0
    def __init__(self, mapper):
        self.artifacts_resource = None
        artifacts_resource = self._get_artifacts_resource()
        reject_method_resource = wsgi.Resource(wsgi.RejectMethodController())

        def _check_json_content_type(environ, result):
            return "application/json" in environ["CONTENT_TYPE"]

        def _check_octet_stream_content_type(environ, result):
            return "application/octet-stream" in environ["CONTENT_TYPE"]

        def connect_routes(m, read_only):
            with m.submapper(resource_name="artifact_operations",
                             path_prefix="/{id}",
                             requirements={'id': UUID_REGEX}) as art:
                art.show()
                if not read_only:
                    art.delete()
                    art.action('update', method='PATCH')
                    art.link('publish', method='POST')

                def connect_attr_action(attr):
                    if not read_only:
                        attr.action("upload",
                                    conditions={
                                        'method': ["POST", "PUT"],
                                        'function':
                                        _check_octet_stream_content_type
                                    })
                        attr.action("update_property",
                                    conditions={
                                        'method': ["POST", "PUT"],
                                        'function': _check_json_content_type
                                    })
                    attr.link("download", method="GET")

                attr_map = art.submapper(resource_name="attr_operations",
                                         path_prefix="/{attr}",
                                         path_left=None)
                attr_items = art.submapper(
                    resource_name="attr_item_ops",
                    path_prefix="/{attr}/{path_left:.*}")
                connect_attr_action(attr_map)
                connect_attr_action(attr_items)

            m.connect("",
                      action='list',
                      conditions={'method': 'GET'},
                      state='active')
            m.connect("/drafts",
                      action='list',
                      conditions={'method': 'GET'},
                      state='creating')
            if not read_only:
                m.connect("/drafts",
                          action='create',
                          conditions={'method': 'POST'})

        mapper.connect('/artifacts',
                       controller=artifacts_resource,
                       action='list_artifact_types',
                       conditions={'method': ['GET']})

        versioned = mapper.submapper(path_prefix='/artifacts/{type_name}/'
                                     'v{type_version}',
                                     controller=artifacts_resource)

        non_versioned = mapper.submapper(path_prefix='/artifacts/{type_name}',
                                         type_version=None,
                                         controller=artifacts_resource)
        connect_routes(versioned, False)
        connect_routes(non_versioned, True)

        mapper.connect(
            '/artifacts',
            controller=reject_method_resource,
            action='reject',
            allowed_methods='GET',
            conditions={'method': ['POST', 'PUT', 'DELETE', 'PATCH', 'HEAD']})

        super(API, self).__init__(mapper)
예제 #3
0
    def __init__(self, mapper):
        custom_image_properties = images.load_custom_properties()
        reject_method_resource = wsgi.Resource(wsgi.RejectMethodController())

        schemas_resource = schemas.create_resource(custom_image_properties)
        mapper.connect('/schemas/image',
                       controller=schemas_resource,
                       action='image',
                       conditions={'method': ['GET']})
        mapper.connect(
            '/schemas/image',
            controller=reject_method_resource,
            action='reject',
            allowed_methods='GET',
            conditions={'method': ['POST', 'PUT', 'DELETE', 'PATCH', 'HEAD']})
        mapper.connect('/schemas/images',
                       controller=schemas_resource,
                       action='images',
                       conditions={'method': ['GET']})
        mapper.connect(
            '/schemas/images',
            controller=reject_method_resource,
            action='reject',
            allowed_methods='GET',
            conditions={'method': ['POST', 'PUT', 'DELETE', 'PATCH', 'HEAD']})
        mapper.connect('/schemas/member',
                       controller=schemas_resource,
                       action='member',
                       conditions={'method': ['GET']})
        mapper.connect(
            '/schemas/member',
            controller=reject_method_resource,
            action='reject',
            allowed_methods='GET',
            conditions={'method': ['POST', 'PUT', 'DELETE', 'PATCH', 'HEAD']})

        mapper.connect('/schemas/members',
                       controller=schemas_resource,
                       action='members',
                       conditions={'method': ['GET']})
        mapper.connect(
            '/schemas/members',
            controller=reject_method_resource,
            action='reject',
            allowed_methods='GET',
            conditions={'method': ['POST', 'PUT', 'DELETE', 'PATCH', 'HEAD']})

        mapper.connect('/schemas/task',
                       controller=schemas_resource,
                       action='task',
                       conditions={'method': ['GET']})
        mapper.connect(
            '/schemas/task',
            controller=reject_method_resource,
            action='reject',
            allowed_methods='GET',
            conditions={'method': ['POST', 'PUT', 'DELETE', 'PATCH', 'HEAD']})
        mapper.connect('/schemas/tasks',
                       controller=schemas_resource,
                       action='tasks',
                       conditions={'method': ['GET']})
        mapper.connect(
            '/schemas/tasks',
            controller=reject_method_resource,
            action='reject',
            allowed_methods='GET',
            conditions={'method': ['POST', 'PUT', 'DELETE', 'PATCH', 'HEAD']})

        mapper.connect('/schemas/metadefs/namespace',
                       controller=schemas_resource,
                       action='metadef_namespace',
                       conditions={'method': ['GET']})
        mapper.connect(
            '/schemas/metadefs/namespace',
            controller=reject_method_resource,
            action='reject',
            allowed_methods='GET',
            conditions={'method': ['POST', 'PUT', 'DELETE', 'PATCH', 'HEAD']})

        mapper.connect('/schemas/metadefs/namespaces',
                       controller=schemas_resource,
                       action='metadef_namespaces',
                       conditions={'method': ['GET']})
        mapper.connect(
            '/schemas/metadefs/namespaces',
            controller=reject_method_resource,
            action='reject',
            allowed_methods='GET',
            conditions={'method': ['POST', 'PUT', 'DELETE', 'PATCH', 'HEAD']})

        mapper.connect('/schemas/metadefs/resource_type',
                       controller=schemas_resource,
                       action='metadef_resource_type',
                       conditions={'method': ['GET']})
        mapper.connect(
            '/schemas/metadefs/resource_type',
            controller=reject_method_resource,
            action='reject',
            allowed_methods='GET',
            conditions={'method': ['POST', 'PUT', 'DELETE', 'PATCH', 'HEAD']})

        mapper.connect('/schemas/metadefs/resource_types',
                       controller=schemas_resource,
                       action='metadef_resource_types',
                       conditions={'method': ['GET']})
        mapper.connect(
            '/schemas/metadefs/resource_types',
            controller=reject_method_resource,
            action='reject',
            allowed_methods='GET',
            conditions={'method': ['POST', 'PUT', 'DELETE', 'PATCH', 'HEAD']})

        mapper.connect('/schemas/metadefs/property',
                       controller=schemas_resource,
                       action='metadef_property',
                       conditions={'method': ['GET']})
        mapper.connect(
            '/schemas/metadefs/property',
            controller=reject_method_resource,
            action='reject',
            allowed_methods='GET',
            conditions={'method': ['POST', 'PUT', 'DELETE', 'PATCH', 'HEAD']})

        mapper.connect('/schemas/metadefs/properties',
                       controller=schemas_resource,
                       action='metadef_properties',
                       conditions={'method': ['GET']})
        mapper.connect(
            '/schemas/metadefs/properties',
            controller=reject_method_resource,
            action='reject',
            allowed_methods='GET',
            conditions={'method': ['POST', 'PUT', 'DELETE', 'PATCH', 'HEAD']})

        mapper.connect('/schemas/metadefs/object',
                       controller=schemas_resource,
                       action='metadef_object',
                       conditions={'method': ['GET']})
        mapper.connect(
            '/schemas/metadefs/object',
            controller=reject_method_resource,
            action='reject',
            allowed_methods='GET',
            conditions={'method': ['POST', 'PUT', 'DELETE', 'PATCH', 'HEAD']})

        mapper.connect('/schemas/metadefs/objects',
                       controller=schemas_resource,
                       action='metadef_objects',
                       conditions={'method': ['GET']})
        mapper.connect(
            '/schemas/metadefs/objects',
            controller=reject_method_resource,
            action='reject',
            allowed_methods='GET',
            conditions={'method': ['POST', 'PUT', 'DELETE', 'PATCH', 'HEAD']})

        mapper.connect('/schemas/metadefs/tag',
                       controller=schemas_resource,
                       action='metadef_tag',
                       conditions={'method': ['GET']})
        mapper.connect(
            '/schemas/metadefs/tag',
            controller=reject_method_resource,
            action='reject',
            allowed_methods='GET',
            conditions={'method': ['POST', 'PUT', 'DELETE', 'PATCH', 'HEAD']})

        mapper.connect('/schemas/metadefs/tags',
                       controller=schemas_resource,
                       action='metadef_tags',
                       conditions={'method': ['GET']})
        mapper.connect(
            '/schemas/metadefs/tags',
            controller=reject_method_resource,
            action='reject',
            allowed_methods='GET',
            conditions={'method': ['POST', 'PUT', 'DELETE', 'PATCH', 'HEAD']})

        # Metadef resource types
        metadef_resource_types_resource = (
            metadef_resource_types.create_resource())

        mapper.connect('/metadefs/resource_types',
                       controller=metadef_resource_types_resource,
                       action='index',
                       conditions={'method': ['GET']})
        mapper.connect(
            '/metadefs/resource_types',
            controller=reject_method_resource,
            action='reject',
            allowed_methods='GET',
            conditions={'method': ['POST', 'PUT', 'DELETE', 'PATCH', 'HEAD']})

        mapper.connect('/metadefs/namespaces/{namespace}/resource_types',
                       controller=metadef_resource_types_resource,
                       action='show',
                       conditions={'method': ['GET']})
        mapper.connect('/metadefs/namespaces/{namespace}/resource_types',
                       controller=metadef_resource_types_resource,
                       action='create',
                       conditions={'method': ['POST']})
        mapper.connect(
            '/metadefs/namespaces/{namespace}/resource_types',
            controller=reject_method_resource,
            action='reject',
            allowed_methods='GET, POST',
            conditions={'method': ['PUT', 'DELETE', 'PATCH', 'HEAD']})

        mapper.connect(
            '/metadefs/namespaces/{namespace}/resource_types/'
            '{resource_type}',
            controller=metadef_resource_types_resource,
            action='delete',
            conditions={'method': ['DELETE']})
        mapper.connect(
            '/metadefs/namespaces/{namespace}/resource_types/'
            '{resource_type}',
            controller=reject_method_resource,
            action='reject',
            allowed_methods='DELETE',
            conditions={'method': ['GET', 'POST', 'PUT', 'PATCH', 'HEAD']})

        # Metadef Namespaces
        metadef_namespace_resource = metadef_namespaces.create_resource()
        mapper.connect('/metadefs/namespaces',
                       controller=metadef_namespace_resource,
                       action='index',
                       conditions={'method': ['GET']})
        mapper.connect('/metadefs/namespaces',
                       controller=metadef_namespace_resource,
                       action='create',
                       conditions={'method': ['POST']})
        mapper.connect(
            '/metadefs/namespaces',
            controller=reject_method_resource,
            action='reject',
            allowed_methods='GET, POST',
            conditions={'method': ['PUT', 'DELETE', 'PATCH', 'HEAD']})

        mapper.connect('/metadefs/namespaces/{namespace}',
                       controller=metadef_namespace_resource,
                       action='show',
                       conditions={'method': ['GET']})
        mapper.connect('/metadefs/namespaces/{namespace}',
                       controller=metadef_namespace_resource,
                       action='update',
                       conditions={'method': ['PUT']})
        mapper.connect('/metadefs/namespaces/{namespace}',
                       controller=metadef_namespace_resource,
                       action='delete',
                       conditions={'method': ['DELETE']})
        mapper.connect('/metadefs/namespaces/{namespace}',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET, PUT, DELETE',
                       conditions={'method': ['POST', 'PATCH', 'HEAD']})

        # Metadef namespace properties
        metadef_properties_resource = metadef_properties.create_resource()
        mapper.connect('/metadefs/namespaces/{namespace}/properties',
                       controller=metadef_properties_resource,
                       action='index',
                       conditions={'method': ['GET']})
        mapper.connect('/metadefs/namespaces/{namespace}/properties',
                       controller=metadef_properties_resource,
                       action='create',
                       conditions={'method': ['POST']})
        mapper.connect('/metadefs/namespaces/{namespace}/properties',
                       controller=metadef_namespace_resource,
                       action='delete_properties',
                       conditions={'method': ['DELETE']})
        mapper.connect('/metadefs/namespaces/{namespace}/properties',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET, POST, DELETE',
                       conditions={'method': ['PUT', 'PATCH', 'HEAD']})

        mapper.connect(
            '/metadefs/namespaces/{namespace}/properties/{'
            'property_name}',
            controller=metadef_properties_resource,
            action='show',
            conditions={'method': ['GET']})
        mapper.connect(
            '/metadefs/namespaces/{namespace}/properties/{'
            'property_name}',
            controller=metadef_properties_resource,
            action='update',
            conditions={'method': ['PUT']})
        mapper.connect(
            '/metadefs/namespaces/{namespace}/properties/{'
            'property_name}',
            controller=metadef_properties_resource,
            action='delete',
            conditions={'method': ['DELETE']})
        mapper.connect(
            '/metadefs/namespaces/{namespace}/properties/{'
            'property_name}',
            controller=reject_method_resource,
            action='reject',
            allowed_methods='GET, PUT, DELETE',
            conditions={'method': ['POST', 'PATCH', 'HEAD']})

        # Metadef objects
        metadef_objects_resource = metadef_objects.create_resource()
        mapper.connect('/metadefs/namespaces/{namespace}/objects',
                       controller=metadef_objects_resource,
                       action='index',
                       conditions={'method': ['GET']})
        mapper.connect('/metadefs/namespaces/{namespace}/objects',
                       controller=metadef_objects_resource,
                       action='create',
                       conditions={'method': ['POST']})
        mapper.connect('/metadefs/namespaces/{namespace}/objects',
                       controller=metadef_namespace_resource,
                       action='delete_objects',
                       conditions={'method': ['DELETE']})
        mapper.connect('/metadefs/namespaces/{namespace}/objects',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET, POST, DELETE',
                       conditions={'method': ['PUT', 'PATCH', 'HEAD']})

        mapper.connect(
            '/metadefs/namespaces/{namespace}/objects/{'
            'object_name}',
            controller=metadef_objects_resource,
            action='show',
            conditions={'method': ['GET']})
        mapper.connect(
            '/metadefs/namespaces/{namespace}/objects/{'
            'object_name}',
            controller=metadef_objects_resource,
            action='update',
            conditions={'method': ['PUT']})
        mapper.connect(
            '/metadefs/namespaces/{namespace}/objects/{'
            'object_name}',
            controller=metadef_objects_resource,
            action='delete',
            conditions={'method': ['DELETE']})
        mapper.connect(
            '/metadefs/namespaces/{namespace}/objects/{'
            'object_name}',
            controller=reject_method_resource,
            action='reject',
            allowed_methods='GET, PUT, DELETE',
            conditions={'method': ['POST', 'PATCH', 'HEAD']})

        # Metadef tags
        metadef_tags_resource = metadef_tags.create_resource()
        mapper.connect('/metadefs/namespaces/{namespace}/tags',
                       controller=metadef_tags_resource,
                       action='index',
                       conditions={'method': ['GET']})
        mapper.connect('/metadefs/namespaces/{namespace}/tags',
                       controller=metadef_tags_resource,
                       action='create_tags',
                       conditions={'method': ['POST']})
        mapper.connect('/metadefs/namespaces/{namespace}/tags',
                       controller=metadef_namespace_resource,
                       action='delete_tags',
                       conditions={'method': ['DELETE']})
        mapper.connect('/metadefs/namespaces/{namespace}/tags',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET, POST, DELETE',
                       conditions={'method': ['PUT', 'PATCH', 'HEAD']})

        mapper.connect('/metadefs/namespaces/{namespace}/tags/{tag_name}',
                       controller=metadef_tags_resource,
                       action='show',
                       conditions={'method': ['GET']})
        mapper.connect('/metadefs/namespaces/{namespace}/tags/{tag_name}',
                       controller=metadef_tags_resource,
                       action='create',
                       conditions={'method': ['POST']})
        mapper.connect('/metadefs/namespaces/{namespace}/tags/{tag_name}',
                       controller=metadef_tags_resource,
                       action='update',
                       conditions={'method': ['PUT']})
        mapper.connect('/metadefs/namespaces/{namespace}/tags/{tag_name}',
                       controller=metadef_tags_resource,
                       action='delete',
                       conditions={'method': ['DELETE']})
        mapper.connect('/metadefs/namespaces/{namespace}/tags/{tag_name}',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET, POST, PUT, DELETE',
                       conditions={'method': ['PATCH', 'HEAD']})

        images_resource = images.create_resource(custom_image_properties)
        mapper.connect('/images',
                       controller=images_resource,
                       action='index',
                       conditions={'method': ['GET']})
        mapper.connect('/images',
                       controller=images_resource,
                       action='create',
                       conditions={'method': ['POST']})
        mapper.connect(
            '/images',
            controller=reject_method_resource,
            action='reject',
            allowed_methods='GET, POST',
            conditions={'method': ['PUT', 'DELETE', 'PATCH', 'HEAD']})

        mapper.connect('/images/{image_id}',
                       controller=images_resource,
                       action='update',
                       conditions={'method': ['PATCH']})
        mapper.connect('/images/{image_id}',
                       controller=images_resource,
                       action='show',
                       conditions={'method': ['GET']})
        mapper.connect('/images/{image_id}',
                       controller=images_resource,
                       action='delete',
                       conditions={'method': ['DELETE']})
        mapper.connect('/images/{image_id}',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET, PATCH, DELETE',
                       conditions={'method': ['POST', 'PUT', 'HEAD']})

        image_actions_resource = image_actions.create_resource()
        mapper.connect('/images/{image_id}/actions/deactivate',
                       controller=image_actions_resource,
                       action='deactivate',
                       conditions={'method': ['POST']})
        mapper.connect('/images/{image_id}/actions/reactivate',
                       controller=image_actions_resource,
                       action='reactivate',
                       conditions={'method': ['POST']})
        mapper.connect(
            '/images/{image_id}/actions/deactivate',
            controller=reject_method_resource,
            action='reject',
            allowed_methods='POST',
            conditions={'method': ['GET', 'PUT', 'DELETE', 'PATCH', 'HEAD']})
        mapper.connect(
            '/images/{image_id}/actions/reactivate',
            controller=reject_method_resource,
            action='reject',
            allowed_methods='POST',
            conditions={'method': ['GET', 'PUT', 'DELETE', 'PATCH', 'HEAD']})

        image_data_resource = image_data.create_resource()
        mapper.connect('/images/{image_id}/file',
                       controller=image_data_resource,
                       action='download',
                       conditions={'method': ['GET']})
        mapper.connect('/images/{image_id}/file',
                       controller=image_data_resource,
                       action='upload',
                       conditions={'method': ['PUT']})
        mapper.connect(
            '/images/{image_id}/file',
            controller=reject_method_resource,
            action='reject',
            allowed_methods='GET, PUT',
            conditions={'method': ['POST', 'DELETE', 'PATCH', 'HEAD']})

        image_tags_resource = image_tags.create_resource()
        mapper.connect('/images/{image_id}/tags/{tag_value}',
                       controller=image_tags_resource,
                       action='update',
                       conditions={'method': ['PUT']})
        mapper.connect('/images/{image_id}/tags/{tag_value}',
                       controller=image_tags_resource,
                       action='delete',
                       conditions={'method': ['DELETE']})
        mapper.connect('/images/{image_id}/tags/{tag_value}',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='PUT, DELETE',
                       conditions={'method': ['GET', 'POST', 'PATCH', 'HEAD']})

        image_members_resource = image_members.create_resource()
        mapper.connect('/images/{image_id}/members',
                       controller=image_members_resource,
                       action='index',
                       conditions={'method': ['GET']})
        mapper.connect('/images/{image_id}/members',
                       controller=image_members_resource,
                       action='create',
                       conditions={'method': ['POST']})
        mapper.connect(
            '/images/{image_id}/members',
            controller=reject_method_resource,
            action='reject',
            allowed_methods='GET, POST',
            conditions={'method': ['PUT', 'DELETE', 'PATCH', 'HEAD']})

        mapper.connect('/images/{image_id}/members/{member_id}',
                       controller=image_members_resource,
                       action='show',
                       conditions={'method': ['GET']})
        mapper.connect('/images/{image_id}/members/{member_id}',
                       controller=image_members_resource,
                       action='update',
                       conditions={'method': ['PUT']})
        mapper.connect('/images/{image_id}/members/{member_id}',
                       controller=image_members_resource,
                       action='delete',
                       conditions={'method': ['DELETE']})
        mapper.connect('/images/{image_id}/members/{member_id}',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET, PUT, DELETE',
                       conditions={'method': ['POST', 'PATCH', 'HEAD']})

        tasks_resource = tasks.create_resource()
        mapper.connect('/tasks',
                       controller=tasks_resource,
                       action='create',
                       conditions={'method': ['POST']})
        mapper.connect('/tasks',
                       controller=tasks_resource,
                       action='index',
                       conditions={'method': ['GET']})
        mapper.connect(
            '/tasks',
            controller=reject_method_resource,
            action='reject',
            allowed_methods='GET, POST',
            conditions={'method': ['PUT', 'DELETE', 'PATCH', 'HEAD']})

        mapper.connect('/tasks/{task_id}',
                       controller=tasks_resource,
                       action='get',
                       conditions={'method': ['GET']})
        mapper.connect('/tasks/{task_id}',
                       controller=tasks_resource,
                       action='delete',
                       conditions={'method': ['DELETE']})
        mapper.connect('/tasks/{task_id}',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET, DELETE',
                       conditions={'method': ['POST', 'PUT', 'PATCH', 'HEAD']})

        super(API, self).__init__(mapper)
예제 #4
0
파일: router.py 프로젝트: yebinama/glance
    def __init__(self, mapper):
        reject_method_resource = wsgi.Resource(wsgi.RejectMethodController())

        mapper.connect("/", controller=reject_method_resource, action="reject")

        super(API, self).__init__(mapper)
예제 #5
0
def init(mapper):
    reject_resource = wsgi.Resource(wsgi.RejectMethodController())
    mapper.connect("/v1", controller=reject_resource,
                   action="reject")
예제 #6
0
파일: router.py 프로젝트: anlaneg/glance
    def __init__(self, mapper):
        #载入schema-image.json
        custom_image_properties = images.load_custom_properties()
        #声明reject Controller
        reject_method_resource = wsgi.Resource(wsgi.RejectMethodController())

        schemas_resource = schemas.create_resource(custom_image_properties)
        #'/schemas/image'将匹配schemas_resource这个controller,并调用其对应的方法'image'
        #对此路径的匹配限制是,方法必须为'GET'
        mapper.connect('/schemas/image',
                       controller=schemas_resource,
                       action='image',
                       conditions={'method': ['GET']},
                       body_reject=True)
        #除GET方法外,其它均调用reject_method_resource的reject方法
        mapper.connect('/schemas/image',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET')
        mapper.connect('/schemas/images',
                       controller=schemas_resource,
                       action='images',
                       conditions={'method': ['GET']},
                       body_reject=True)
        mapper.connect('/schemas/images',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET')
        mapper.connect('/schemas/member',
                       controller=schemas_resource,
                       action='member',
                       conditions={'method': ['GET']},
                       body_reject=True)
        mapper.connect('/schemas/member',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET')

        mapper.connect('/schemas/members',
                       controller=schemas_resource,
                       action='members',
                       conditions={'method': ['GET']},
                       body_reject=True)
        mapper.connect('/schemas/members',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET')

        mapper.connect('/schemas/task',
                       controller=schemas_resource,
                       action='task',
                       conditions={'method': ['GET']})
        mapper.connect('/schemas/task',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET')
        mapper.connect('/schemas/tasks',
                       controller=schemas_resource,
                       action='tasks',
                       conditions={'method': ['GET']})
        mapper.connect('/schemas/tasks',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET')

        mapper.connect('/schemas/metadefs/namespace',
                       controller=schemas_resource,
                       action='metadef_namespace',
                       conditions={'method': ['GET']},
                       body_reject=True)
        mapper.connect('/schemas/metadefs/namespace',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET')

        mapper.connect('/schemas/metadefs/namespaces',
                       controller=schemas_resource,
                       action='metadef_namespaces',
                       conditions={'method': ['GET']},
                       body_reject=True)
        mapper.connect('/schemas/metadefs/namespaces',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET')

        mapper.connect('/schemas/metadefs/resource_type',
                       controller=schemas_resource,
                       action='metadef_resource_type',
                       conditions={'method': ['GET']},
                       body_reject=True)
        mapper.connect('/schemas/metadefs/resource_type',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET')

        mapper.connect('/schemas/metadefs/resource_types',
                       controller=schemas_resource,
                       action='metadef_resource_types',
                       conditions={'method': ['GET']},
                       body_reject=True)
        mapper.connect('/schemas/metadefs/resource_types',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET')

        mapper.connect('/schemas/metadefs/property',
                       controller=schemas_resource,
                       action='metadef_property',
                       conditions={'method': ['GET']},
                       body_reject=True)
        mapper.connect('/schemas/metadefs/property',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET')

        mapper.connect('/schemas/metadefs/properties',
                       controller=schemas_resource,
                       action='metadef_properties',
                       conditions={'method': ['GET']},
                       body_reject=True)
        mapper.connect('/schemas/metadefs/properties',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET')

        mapper.connect('/schemas/metadefs/object',
                       controller=schemas_resource,
                       action='metadef_object',
                       conditions={'method': ['GET']},
                       body_reject=True)
        mapper.connect('/schemas/metadefs/object',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET')

        mapper.connect('/schemas/metadefs/objects',
                       controller=schemas_resource,
                       action='metadef_objects',
                       conditions={'method': ['GET']},
                       body_reject=True)
        mapper.connect('/schemas/metadefs/objects',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET')

        mapper.connect('/schemas/metadefs/tag',
                       controller=schemas_resource,
                       action='metadef_tag',
                       conditions={'method': ['GET']},
                       body_reject=True)
        mapper.connect('/schemas/metadefs/tag',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET')

        mapper.connect('/schemas/metadefs/tags',
                       controller=schemas_resource,
                       action='metadef_tags',
                       conditions={'method': ['GET']},
                       body_reject=True)
        mapper.connect('/schemas/metadefs/tags',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET')

        # Metadef resource types
        metadef_resource_types_resource = (
            metadef_resource_types.create_resource())

        mapper.connect('/metadefs/resource_types',
                       controller=metadef_resource_types_resource,
                       action='index',
                       conditions={'method': ['GET']},
                       body_reject=True)
        mapper.connect('/metadefs/resource_types',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET')

        mapper.connect('/metadefs/namespaces/{namespace}/resource_types',
                       controller=metadef_resource_types_resource,
                       action='show',
                       conditions={'method': ['GET']},
                       body_reject=True)
        mapper.connect('/metadefs/namespaces/{namespace}/resource_types',
                       controller=metadef_resource_types_resource,
                       action='create',
                       conditions={'method': ['POST']})
        mapper.connect('/metadefs/namespaces/{namespace}/resource_types',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET, POST')

        mapper.connect(
            '/metadefs/namespaces/{namespace}/resource_types/'
            '{resource_type}',
            controller=metadef_resource_types_resource,
            action='delete',
            conditions={'method': ['DELETE']},
            body_reject=True)
        mapper.connect(
            '/metadefs/namespaces/{namespace}/resource_types/'
            '{resource_type}',
            controller=reject_method_resource,
            action='reject',
            allowed_methods='DELETE')

        # Metadef Namespaces
        metadef_namespace_resource = metadef_namespaces.create_resource()
        mapper.connect('/metadefs/namespaces',
                       controller=metadef_namespace_resource,
                       action='index',
                       conditions={'method': ['GET']})
        mapper.connect('/metadefs/namespaces',
                       controller=metadef_namespace_resource,
                       action='create',
                       conditions={'method': ['POST']})
        mapper.connect('/metadefs/namespaces',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET, POST')

        mapper.connect('/metadefs/namespaces/{namespace}',
                       controller=metadef_namespace_resource,
                       action='show',
                       conditions={'method': ['GET']},
                       body_reject=True)
        mapper.connect('/metadefs/namespaces/{namespace}',
                       controller=metadef_namespace_resource,
                       action='update',
                       conditions={'method': ['PUT']})
        mapper.connect('/metadefs/namespaces/{namespace}',
                       controller=metadef_namespace_resource,
                       action='delete',
                       conditions={'method': ['DELETE']},
                       body_reject=True)
        mapper.connect('/metadefs/namespaces/{namespace}',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET, PUT, DELETE')

        # Metadef namespace properties
        metadef_properties_resource = metadef_properties.create_resource()
        mapper.connect('/metadefs/namespaces/{namespace}/properties',
                       controller=metadef_properties_resource,
                       action='index',
                       conditions={'method': ['GET']},
                       body_reject=True)
        mapper.connect('/metadefs/namespaces/{namespace}/properties',
                       controller=metadef_properties_resource,
                       action='create',
                       conditions={'method': ['POST']})
        mapper.connect('/metadefs/namespaces/{namespace}/properties',
                       controller=metadef_namespace_resource,
                       action='delete_properties',
                       conditions={'method': ['DELETE']})
        mapper.connect('/metadefs/namespaces/{namespace}/properties',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET, POST, DELETE')

        mapper.connect(
            '/metadefs/namespaces/{namespace}/properties/{'
            'property_name}',
            controller=metadef_properties_resource,
            action='show',
            conditions={'method': ['GET']})
        mapper.connect(
            '/metadefs/namespaces/{namespace}/properties/{'
            'property_name}',
            controller=metadef_properties_resource,
            action='update',
            conditions={'method': ['PUT']})
        mapper.connect(
            '/metadefs/namespaces/{namespace}/properties/{'
            'property_name}',
            controller=metadef_properties_resource,
            action='delete',
            conditions={'method': ['DELETE']})
        mapper.connect(
            '/metadefs/namespaces/{namespace}/properties/{'
            'property_name}',
            controller=reject_method_resource,
            action='reject',
            allowed_methods='GET, PUT, DELETE')

        # Metadef objects
        metadef_objects_resource = metadef_objects.create_resource()
        mapper.connect('/metadefs/namespaces/{namespace}/objects',
                       controller=metadef_objects_resource,
                       action='index',
                       conditions={'method': ['GET']})
        mapper.connect('/metadefs/namespaces/{namespace}/objects',
                       controller=metadef_objects_resource,
                       action='create',
                       conditions={'method': ['POST']})
        mapper.connect('/metadefs/namespaces/{namespace}/objects',
                       controller=metadef_namespace_resource,
                       action='delete_objects',
                       conditions={'method': ['DELETE']})
        mapper.connect('/metadefs/namespaces/{namespace}/objects',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET, POST, DELETE')

        mapper.connect(
            '/metadefs/namespaces/{namespace}/objects/{'
            'object_name}',
            controller=metadef_objects_resource,
            action='show',
            conditions={'method': ['GET']},
            body_reject=True)
        mapper.connect(
            '/metadefs/namespaces/{namespace}/objects/{'
            'object_name}',
            controller=metadef_objects_resource,
            action='update',
            conditions={'method': ['PUT']})
        mapper.connect(
            '/metadefs/namespaces/{namespace}/objects/{'
            'object_name}',
            controller=metadef_objects_resource,
            action='delete',
            conditions={'method': ['DELETE']},
            body_reject=True)
        mapper.connect(
            '/metadefs/namespaces/{namespace}/objects/{'
            'object_name}',
            controller=reject_method_resource,
            action='reject',
            allowed_methods='GET, PUT, DELETE')

        # Metadef tags
        metadef_tags_resource = metadef_tags.create_resource()
        mapper.connect('/metadefs/namespaces/{namespace}/tags',
                       controller=metadef_tags_resource,
                       action='index',
                       conditions={'method': ['GET']})
        mapper.connect('/metadefs/namespaces/{namespace}/tags',
                       controller=metadef_tags_resource,
                       action='create_tags',
                       conditions={'method': ['POST']})
        mapper.connect('/metadefs/namespaces/{namespace}/tags',
                       controller=metadef_namespace_resource,
                       action='delete_tags',
                       conditions={'method': ['DELETE']})
        mapper.connect('/metadefs/namespaces/{namespace}/tags',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET, POST, DELETE')

        mapper.connect('/metadefs/namespaces/{namespace}/tags/{tag_name}',
                       controller=metadef_tags_resource,
                       action='show',
                       conditions={'method': ['GET']},
                       body_reject=True)
        mapper.connect('/metadefs/namespaces/{namespace}/tags/{tag_name}',
                       controller=metadef_tags_resource,
                       action='create',
                       conditions={'method': ['POST']},
                       body_reject=True)
        mapper.connect('/metadefs/namespaces/{namespace}/tags/{tag_name}',
                       controller=metadef_tags_resource,
                       action='update',
                       conditions={'method': ['PUT']})
        mapper.connect('/metadefs/namespaces/{namespace}/tags/{tag_name}',
                       controller=metadef_tags_resource,
                       action='delete',
                       conditions={'method': ['DELETE']},
                       body_reject=True)
        mapper.connect('/metadefs/namespaces/{namespace}/tags/{tag_name}',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET, POST, PUT, DELETE')

        #创建对image操作的Controller
        images_resource = images.create_resource(custom_image_properties)
        #将get方法映射至'index'
        mapper.connect('/images',
                       controller=images_resource,
                       action='index',
                       conditions={'method': ['GET']})
        #将post方法映射到'create'
        mapper.connect('/images',
                       controller=images_resource,
                       action='create',
                       conditions={'method': ['POST']})
        mapper.connect('/images',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET, POST')

        mapper.connect('/images/{image_id}',
                       controller=images_resource,
                       action='update',
                       conditions={'method': ['PATCH']})
        mapper.connect('/images/{image_id}',
                       controller=images_resource,
                       action='show',
                       conditions={'method': ['GET']},
                       body_reject=True)
        mapper.connect('/images/{image_id}',
                       controller=images_resource,
                       action='delete',
                       conditions={'method': ['DELETE']},
                       body_reject=True)
        mapper.connect('/images/{image_id}',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET, PATCH, DELETE')
        mapper.connect('/images/{image_id}/import',
                       controller=images_resource,
                       action='import_image',
                       conditions={'method': ['POST']})
        mapper.connect('/images/{image_id}/import',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='POST')

        image_actions_resource = image_actions.create_resource()
        mapper.connect('/images/{image_id}/actions/deactivate',
                       controller=image_actions_resource,
                       action='deactivate',
                       conditions={'method': ['POST']},
                       body_reject=True)
        mapper.connect('/images/{image_id}/actions/reactivate',
                       controller=image_actions_resource,
                       action='reactivate',
                       conditions={'method': ['POST']},
                       body_reject=True)
        mapper.connect('/images/{image_id}/actions/deactivate',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='POST')
        mapper.connect('/images/{image_id}/actions/reactivate',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='POST')

        #image数据的上传下载
        image_data_resource = image_data.create_resource()
        mapper.connect('/images/{image_id}/file',
                       controller=image_data_resource,
                       action='download',
                       conditions={'method': ['GET']},
                       body_reject=True)
        mapper.connect('/images/{image_id}/file',
                       controller=image_data_resource,
                       action='upload',
                       conditions={'method': ['PUT']})
        mapper.connect('/images/{image_id}/file',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET, PUT')
        mapper.connect('/images/{image_id}/stage',
                       controller=image_data_resource,
                       action='stage',
                       conditions={'method': ['PUT']})
        mapper.connect('/images/{image_id}/stage',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='PUT')

        image_tags_resource = image_tags.create_resource()
        mapper.connect('/images/{image_id}/tags/{tag_value}',
                       controller=image_tags_resource,
                       action='update',
                       conditions={'method': ['PUT']},
                       body_reject=True)
        mapper.connect('/images/{image_id}/tags/{tag_value}',
                       controller=image_tags_resource,
                       action='delete',
                       conditions={'method': ['DELETE']},
                       body_reject=True)
        mapper.connect('/images/{image_id}/tags/{tag_value}',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='PUT, DELETE')

        image_members_resource = image_members.create_resource()
        mapper.connect('/images/{image_id}/members',
                       controller=image_members_resource,
                       action='index',
                       conditions={'method': ['GET']},
                       body_reject=True)
        mapper.connect('/images/{image_id}/members',
                       controller=image_members_resource,
                       action='create',
                       conditions={'method': ['POST']})
        mapper.connect('/images/{image_id}/members',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET, POST')

        mapper.connect('/images/{image_id}/members/{member_id}',
                       controller=image_members_resource,
                       action='show',
                       conditions={'method': ['GET']},
                       body_reject=True)
        mapper.connect('/images/{image_id}/members/{member_id}',
                       controller=image_members_resource,
                       action='update',
                       conditions={'method': ['PUT']})
        mapper.connect('/images/{image_id}/members/{member_id}',
                       controller=image_members_resource,
                       action='delete',
                       conditions={'method': ['DELETE']},
                       body_reject=True)
        mapper.connect('/images/{image_id}/members/{member_id}',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET, PUT, DELETE')

        tasks_resource = tasks.create_resource()
        mapper.connect('/tasks',
                       controller=tasks_resource,
                       action='create',
                       conditions={'method': ['POST']})
        mapper.connect('/tasks',
                       controller=tasks_resource,
                       action='index',
                       conditions={'method': ['GET']})
        mapper.connect('/tasks',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET, POST')

        mapper.connect('/tasks/{task_id}',
                       controller=tasks_resource,
                       action='get',
                       conditions={'method': ['GET']})
        mapper.connect('/tasks/{task_id}',
                       controller=tasks_resource,
                       action='delete',
                       conditions={'method': ['DELETE']})
        mapper.connect('/tasks/{task_id}',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET, DELETE')

        # Discovery API
        info_resource = discovery.create_resource()
        mapper.connect('/info/import',
                       controller=info_resource,
                       action='get_image_import',
                       conditions={'method': ['GET']},
                       body_reject=True)
        mapper.connect('/info/import',
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET')

        super(API, self).__init__(mapper)
예제 #7
0
    def __init__(self, mapper):
        reject_method_resource = wsgi.Resource(wsgi.RejectMethodController())

        images_resource = images.create_resource()

        mapper.connect("/",
                       controller=images_resource,
                       action="index")
        mapper.connect("/images",
                       controller=images_resource,
                       action='index',
                       conditions={'method': ['GET']})
        mapper.connect("/images",
                       controller=images_resource,
                       action='create',
                       conditions={'method': ['POST']})
        mapper.connect("/images",
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET, POST')
        mapper.connect("/images/detail",
                       controller=images_resource,
                       action='detail',
                       conditions={'method': ['GET', 'HEAD']})
        mapper.connect("/images/detail",
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET, HEAD')
        mapper.connect("/images/{id}",
                       controller=images_resource,
                       action="meta",
                       conditions=dict(method=["HEAD"]))
        mapper.connect("/images/{id}",
                       controller=images_resource,
                       action="show",
                       conditions=dict(method=["GET"]))
        mapper.connect("/images/{id}",
                       controller=images_resource,
                       action="update",
                       conditions=dict(method=["PUT"]))
        mapper.connect("/images/{id}",
                       controller=images_resource,
                       action="delete",
                       conditions=dict(method=["DELETE"]))
        mapper.connect("/images/{id}",
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET, HEAD, PUT, DELETE')

        members_resource = members.create_resource()

        mapper.connect("/images/{image_id}/members",
                       controller=members_resource,
                       action="index",
                       conditions={'method': ['GET']})
        mapper.connect("/images/{image_id}/members",
                       controller=members_resource,
                       action="update_all",
                       conditions=dict(method=["PUT"]))
        mapper.connect("/images/{image_id}/members",
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET, PUT')
        mapper.connect("/images/{image_id}/members/{id}",
                       controller=members_resource,
                       action="show",
                       conditions={'method': ['GET']})
        mapper.connect("/images/{image_id}/members/{id}",
                       controller=members_resource,
                       action="update",
                       conditions={'method': ['PUT']})
        mapper.connect("/images/{image_id}/members/{id}",
                       controller=members_resource,
                       action="delete",
                       conditions={'method': ['DELETE']})
        mapper.connect("/images/{image_id}/members/{id}",
                       controller=reject_method_resource,
                       action='reject',
                       allowed_methods='GET, PUT, DELETE')
        mapper.connect("/shared-images/{id}",
                       controller=members_resource,
                       action="index_shared_images")

        super(API, self).__init__(mapper)