
below issures are removed from ignore cases: E114 indentation is not a multiple of four (comment) E116 unexpected indentation (comment) E121 continuation line under-indented for hanging indent E122 continuation line missing indentation or outdented E123 closing bracket does not match indentation of opening bracket's line E124 closing bracket does not match visual indentation E125 continuation line with same indent as next logical line E126 continuation line over-indented for hanging indent E127 continuation line over-indented for visual indent E128 continuation line under-indented for visual indent E129 visually indented line with same indent as next logical line E131 continuation line unaligned for hanging indent E201 whitespace after '(' E228 missing whitespace around modulo operator E231 missing whitespace after ',' E241 multiple spaces after ':' E251 unexpected spaces around keyword / parameter equals E265 block comment should start with '#' E271 multiple spaces after keyword E302 expected 2 blank lines, found 1 E303 too many blank lines E305 expected 2 blank lines after class or function definition, found 1 E704 multiple statements on one line (def) E713 test for membership should be 'not in' E714 test for object identity should be 'is not' E722 do not use bare except' E731 do not assign a lambda expression, use a def E999 SyntaxError: invalid syntax (this is likely python3) F401 <foo> imported but unused F841 local variable 'foo' is assigned to but never used H201: no 'except:' H233: Python 3.x incompatible use of print operator B001 Do not use bare `except:` B004 Using `hasattr(x, '__call__')` to test if `x` is callable is unreliable. B305 `.next()` is not a thing on Python 3. Use the `next()` builtin. B306 `BaseException.message` has been deprecated as of Python 2.6 and is removed in Python 3. B007 Loop control variable 'key' not used within the loop body. remain below issues in ignores: E402 module level import not at top of file ./service-mgmt-api/sm-api/sm_api/cmd/__init__.py:25 Hxxx since which are related with document format F811 redefinition of unused '<foo>' from line <x> ./service-mgmt-tools/sm-tools/sm_tools/sm_configure.py:18 F821 undefined name 'e' ./service-mgmt-api/sm-api/sm_api/common/utils.py:448 B006 Do not use mutable data structures for argument defaults. ./service-mgmt-api/sm-api/sm_api/common/service.py:59 B008 Do not perform calls in argument defaults. ./service-mgmt-api/sm-api/sm_api/openstack/common/timeutils.py:117 Test have been done:Build,Deploy,some smc command,such as smc service-list, smc service-show, sm-dump, etc Story: 2003430 Task: 26524 Change-Id: I3e2a4a31f87e3ff66cfce86f54285e830ee1c3dc Signed-off-by: Sun Austin <austin.sun@intel.com>
97 lines
2.7 KiB
Python
97 lines
2.7 KiB
Python
#
|
|
# Copyright (c) 2014-2018 Wind River Systems, Inc.
|
|
#
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
|
|
"""
|
|
Hooks
|
|
"""
|
|
|
|
from pecan import hooks
|
|
|
|
from sm_api.common import context
|
|
from sm_api.common import utils
|
|
|
|
from sm_api.common import config
|
|
from sm_api.db import api as dbapi
|
|
from sm_api.openstack.common import policy
|
|
|
|
|
|
class ConfigHook(hooks.PecanHook):
|
|
def __init__(self):
|
|
super(ConfigHook, self).__init__()
|
|
|
|
def before(self, state):
|
|
state.request.config = config.CONF
|
|
|
|
|
|
class DatabaseHook(hooks.PecanHook):
|
|
# JKUNG def __init__(self):
|
|
# super(DatabaseHook, self).__init__()
|
|
# self.database = sqlite3.connect(config.CONF['database']['database'])
|
|
|
|
def before(self, state):
|
|
# state.request.database = self.database
|
|
state.request.dbapi = dbapi.get_instance()
|
|
|
|
# def __del__(self):
|
|
# self.database.close()
|
|
|
|
|
|
class ContextHook(hooks.PecanHook):
|
|
"""Configures a request context and attaches it to the request.
|
|
|
|
The following HTTP request headers are used:
|
|
|
|
X-User-Id or X-User:
|
|
Used for context.user_id.
|
|
|
|
X-Tenant-Id or X-Tenant:
|
|
Used for context.tenant.
|
|
|
|
X-Auth-Token:
|
|
Used for context.auth_token.
|
|
|
|
X-Roles:
|
|
Used for setting context.is_admin flag to either True or False.
|
|
The flag is set to True, if X-Roles contains either an administrator
|
|
or admin substring. Otherwise it is set to False.
|
|
|
|
"""
|
|
|
|
def __init__(self, public_api_routes):
|
|
self.public_api_routes = public_api_routes
|
|
super(ContextHook, self).__init__()
|
|
|
|
def before(self, state):
|
|
user_id = state.request.headers.get('X-User-Id')
|
|
user_id = state.request.headers.get('X-User', user_id)
|
|
tenant = state.request.headers.get('X-Tenant-Id')
|
|
tenant = state.request.headers.get('X-Tenant', tenant)
|
|
domain_id = state.request.headers.get('X-User-Domain-Id')
|
|
domain_name = state.request.headers.get('X-User-Domain-Name')
|
|
auth_token = state.request.headers.get('X-Auth-Token', None)
|
|
creds = {'roles': state.request.headers.get('X-Roles', '').split(',')}
|
|
|
|
is_admin = policy.check('admin', state.request.headers, creds)
|
|
|
|
path = utils.safe_rstrip(state.request.path, '/')
|
|
is_public_api = path in self.public_api_routes
|
|
|
|
state.request.context = context.RequestContext(
|
|
auth_token=auth_token,
|
|
user=user_id,
|
|
tenant=tenant,
|
|
domain_id=domain_id,
|
|
domain_name=domain_name,
|
|
is_admin=is_admin,
|
|
is_public_api=is_public_api)
|
|
|
|
|
|
class RPCHook(hooks.PecanHook):
|
|
"""Attach the rpcapi object to the request so controllers can get to it."""
|
|
|
|
def before(self, state):
|
|
state.request.rpcapi = rpcapi.ConductorAPI()
|