コード例 #1
0
ファイル: test_context.py プロジェクト: pombredanne/climate
 def test_ctx_from_headers(self):
     api_context.ctx_from_headers(self.fake_headers)
     self.context.assert_called_once_with(user_id=u'1',
                                          roles=[u'user_name0',
                                                 u'user_name1'],
                                          tenant_name=u'tenant_name',
                                          auth_token=u'111-111-111',
                                          service_catalog=u'catalog',
                                          tenant_id=u'1',
                                          user_name=u'user_name')
コード例 #2
0
 def test_ctx_from_headers(self):
     self.context = self.patch(context, 'ClimateContext')
     catalog = json.dumps({'nova': 'catalog'})
     self.fake_headers[u'X-Service-Catalog'] = catalog
     api_context.ctx_from_headers(self.fake_headers)
     self.context.assert_called_once_with(
         user_id=u'1',
         roles=[u'user_name0', u'user_name1'],
         project_name=u'project_name',
         auth_token=u'111-111-111',
         service_catalog={u'nova': u'catalog'},
         project_id=u'1',
         user_name=u'user_name')
コード例 #3
0
 def test_ctx_from_headers(self):
     self.context = self.patch(context, 'ClimateContext')
     catalog = json.dumps({'nova': 'catalog'})
     self.fake_headers[u'X-Service-Catalog'] = catalog
     api_context.ctx_from_headers(self.fake_headers)
     self.context.assert_called_once_with(user_id=u'1',
                                          roles=[u'user_name0',
                                                 u'user_name1'],
                                          project_name=u'project_name',
                                          auth_token=u'111-111-111',
                                          service_catalog={
                                              u'nova': u'catalog'},
                                          project_id=u'1',
                                          user_name=u'user_name')
コード例 #4
0
ファイル: utils.py プロジェクト: sbauza/climate
            def handler(**kwargs):
                LOG.debug(_("Rest.route.decorator.handler, kwargs=%s"), kwargs)

                _init_resp_type(file_upload)

                # update status code
                if status:
                    flask.request.status_code = status

                if flask.request.method in ['POST', 'PUT']:
                    kwargs['data'] = request_data()

                with context.ctx_from_headers(flask.request.headers):
                    try:
                        return func(**kwargs)
                    except ex.ClimateException as e:
                        return bad_request(e)
                    except rpc_common.RemoteError as e:
                        try:
                            # NOTE(sbauza): All Manager Exceptions should be
                            #  defined in climate.manager.exceptions
                            cls = getattr(manager_exceptions, e.exc_type)
                        except AttributeError:
                            # We obfuscate all Exceptions but Climate ones for
                            #  security reasons
                            return internal_error(500, 'Internal Server Error',
                                                  e)
                        return render_error_message(cls.code, e.value,
                                                    cls.code)
                    except Exception as e:
                        return internal_error(500, 'Internal Server Error', e)
コード例 #5
0
ファイル: utils.py プロジェクト: frossigneux/blazar
            def handler(**kwargs):
                LOG.debug("Rest.route.decorator.handler, kwargs=%s", kwargs)

                _init_resp_type(file_upload)

                # update status code
                if status:
                    flask.request.status_code = status

                if flask.request.method in ['POST', 'PUT']:
                    kwargs['data'] = request_data()

                with context.ctx_from_headers(flask.request.headers):
                    try:
                        return func(**kwargs)
                    except ex.ClimateException as e:
                        return bad_request(e)
                    except messaging.RemoteError as e:
                        # Get the exception from manager and common exceptions
                        cls = getattr(manager_exceptions, e.exc_type,
                                      getattr(ex, e.exc_type, None))
                        if cls is not None:
                            return render_error_message(cls.code, e.value,
                                                        cls.code)
                        else:
                            # Get the exception from db exceptions and hide
                            # the message because could contain table/column
                            # information
                            cls = getattr(db_exceptions, e.exc_type, None)
                            if cls is not None:
                                return render_error_message(
                                    cls.code,
                                    '{0}: A database error occurred'.format(
                                        cls.__name__),
                                    cls.code)
                            else:
                                # We obfuscate all Exceptions
                                # but Climate ones for
                                # security reasons
                                err = 'Internal Server Error'
                                return internal_error(500, err, e)
                    except Exception as e:
                        return internal_error(500, 'Internal Server Error', e)
コード例 #6
0
ファイル: utils.py プロジェクト: scroiset/climate
            def handler(**kwargs):
                LOG.debug("Rest.route.decorator.handler, kwargs=%s", kwargs)

                _init_resp_type(file_upload)

                # update status code
                if status:
                    flask.request.status_code = status

                if flask.request.method in ['POST', 'PUT']:
                    kwargs['data'] = request_data()

                with context.ctx_from_headers(flask.request.headers):
                    try:
                        return func(**kwargs)
                    except ex.ClimateException as e:
                        return bad_request(e)
                    except Exception as e:
                        return internal_error(500, 'Internal Server Error', e)
コード例 #7
0
ファイル: utils.py プロジェクト: NikolayStarodubtsev/blazar
            def handler(**kwargs):
                LOG.debug("Rest.route.decorator.handler, kwargs=%s", kwargs)

                _init_resp_type(file_upload)

                # update status code
                if status:
                    flask.request.status_code = status

                if flask.request.method in ['POST', 'PUT']:
                    kwargs['data'] = request_data()

                with context.ctx_from_headers(flask.request.headers):
                    try:
                        return func(**kwargs)
                    except ex.ClimateException as e:
                        return bad_request(e)
                    except messaging.RemoteError as e:
                        # Get the exception from manager and common exceptions
                        cls = getattr(manager_exceptions, e.exc_type,
                                      getattr(ex, e.exc_type, None))
                        if cls is not None:
                            return render_error_message(cls.code, e.value,
                                                        cls.code)
                        else:
                            # Get the exception from db exceptions and hide
                            # the message because could contain table/column
                            # information
                            cls = getattr(db_exceptions, e.exc_type, None)
                            if cls is not None:
                                return render_error_message(
                                    cls.code,
                                    '{0}: A database error occurred'.format(
                                        cls.__name__),
                                    cls.code)
                            else:
                                # We obfuscate all Exceptions
                                # but Climate ones for
                                # security reasons
                                err = 'Internal Server Error'
                                return internal_error(500, err, e)
                    except Exception as e:
                        return internal_error(500, 'Internal Server Error', e)
コード例 #8
0
ファイル: utils.py プロジェクト: scroiset/climate
            def handler(**kwargs):
                LOG.debug("Rest.route.decorator.handler, kwargs=%s", kwargs)

                _init_resp_type(file_upload)

                # update status code
                if status:
                    flask.request.status_code = status

                if flask.request.method in ['POST', 'PUT']:
                    kwargs['data'] = request_data()

                with context.ctx_from_headers(flask.request.headers):
                    try:
                        return func(**kwargs)
                    except ex.ClimateException as e:
                        return bad_request(e)
                    except Exception as e:
                        return internal_error(500, 'Internal Server Error', e)
コード例 #9
0
ファイル: hooks.py プロジェクト: NikolayStarodubtsev/blazar
 def before(self, state):
     state.request.context = context.ctx_from_headers(state.request.headers)
     state.request.context.__enter__()
コード例 #10
0
 def before(self, state):
     state.request.context = context.ctx_from_headers(state.request.headers)
     state.request.context.__enter__()
コード例 #11
0
ファイル: test_context.py プロジェクト: sbauza/climate
 def test_ctx_from_headers_with_admin(self):
     self.patch(policy, 'enforce').return_value = True
     ctx = api_context.ctx_from_headers(self.fake_headers)
     self.assertEqual(True, ctx.is_admin)