예제 #1
0
    def _init_routes(self):
        """Initialize hooks and URI routes to resources."""

        catalog = [
            ('/v1', v1_0.public_endpoints(self, self._conf)),
            ('/v1.1', v1_1.public_endpoints(self, self._conf)),
            ('/v2', v2_0.public_endpoints(self, self._conf)),
            ('/', [('', version.Resource())])
        ]

        if self._conf.admin_mode:
            catalog.extend([
                ('/v1', v1_0.private_endpoints(self, self._conf)),
                ('/v1.1', v1_1.private_endpoints(self, self._conf)),
                ('/v2', v2_0.private_endpoints(self, self._conf)),
            ])

        # NOTE(wanghao): Since hook feature has removed after 1.0.0, using
        # middleware instead of it, but for the compatibility with old version,
        # we support them both now. Hook way can be removed after falcon
        # version must be bigger than 1.0.0 in requirements.
        if (d_version.LooseVersion(falcon.__version__) >=
                d_version.LooseVersion("1.0.0")):
            middleware = [FuncMiddleware(hook) for hook in self.before_hooks]
            self.app = falcon.API(middleware=middleware)
        else:
            self.app = falcon.API(before=self.before_hooks)

        self.app.add_error_handler(Exception, self._error_handler)

        for version_path, endpoints in catalog:
            if endpoints:
                for route, resource in endpoints:
                    self.app.add_route(version_path + route, resource)
예제 #2
0
파일: driver.py 프로젝트: ISCAS-VDI/zaqar
    def _init_routes(self):
        """Initialize hooks and URI routes to resources."""

        catalog = [
            ('/v1', v1_0.public_endpoints(self, self._conf)),
            ('/v1.1', v1_1.public_endpoints(self, self._conf)),
            ('/v2', v2_0.public_endpoints(self, self._conf)),
            ('/', [('', version.Resource())])
        ]

        if self._conf.admin_mode:
            catalog.extend([
                ('/v1', v1_0.private_endpoints(self, self._conf)),
                ('/v1.1', v1_1.private_endpoints(self, self._conf)),
                ('/v2', v2_0.private_endpoints(self, self._conf)),
            ])

        # NOTE(wanghao): Since hook feature has removed after 1.0.0, using
        # middleware instead of it, but for the compatibility with old version,
        # we support them both now. Hook way can be removed after falcon
        # version must be bigger than 1.0.0 in requirements.
        if LooseVersion(falcon.__version__) >= LooseVersion("1.0.0"):
            middleware = [FuncMiddleware(hook) for hook in self.before_hooks]
            self.app = falcon.API(middleware=middleware)
        else:
            self.app = falcon.API(before=self.before_hooks)

        self.app.add_error_handler(Exception, self._error_handler)

        for version_path, endpoints in catalog:
            for route, resource in endpoints:
                self.app.add_route(version_path + route, resource)
예제 #3
0
파일: driver.py 프로젝트: rose/zaqar
    def _init_routes(self):
        """Initialize hooks and URI routes to resources."""

        catalog = [
            ('/v1', v1_0.public_endpoints(self, self._conf)),
            ('/v1.1', v1_1.public_endpoints(self, self._conf)),
        ]

        if self._conf.admin_mode:
            catalog.extend([
                ('/v1', v1_0.private_endpoints(self, self._conf)),
                ('/v1.1', v1_1.private_endpoints(self, self._conf)),
            ])

        self.app = falcon.API(before=self.before_hooks)

        for version_path, endpoints in catalog:
            for route, resource in endpoints:
                self.app.add_route(version_path + route, resource)
예제 #4
0
    def _init_routes(self):
        """Initialize hooks and URI routes to resources."""

        catalog = [
            ('/v1', v1_0.public_endpoints(self, self._conf)),
            ('/v1.1', v1_1.public_endpoints(self, self._conf)),
        ]

        if self._conf.admin_mode:
            catalog.extend([
                ('/v1', v1_0.private_endpoints(self, self._conf)),
                ('/v1.1', v1_1.private_endpoints(self, self._conf)),
            ])

        self.app = falcon.API(before=self.before_hooks)

        for version_path, endpoints in catalog:
            for route, resource in endpoints:
                self.app.add_route(version_path + route, resource)