def __init__(self, *args, **kwargs): # By default, we want a cache that can be shared across requests from different users ("public") # and a maximum age of 60 seconds, to keep our TTL low. self.cacheControl = app.config.get("CACHE_CONTROL", "public, max-age=60") self.log = logging.getLogger(self.__class__.__name__) MethodView.__init__(self, *args, **kwargs)
def handle_jwt(view: MethodView): jwt = request.headers.get('Authorization', None) if jwt is None or len(jwt) == 0: raise exception.api.Unauthorized('请先登录') try: decoded_jwt = authorization.toolkit.decode_jwt_token(jwt) # except InvalidAudienceError: # raise exception.api.Forbidden('您无权进行这个操作') # except InvalidIssuerError: # raise exception.api.Unauthorized('请先登录') except PyJWTError: raise exception.api.Unauthorized('请先登录') if 'id' not in decoded_jwt.keys(): raise exception.api.Unauthorized('请先登录') if 'uuid' not in decoded_jwt.keys(): raise exception.api.Unauthorized('请先登录') user_id = decoded_jwt.get('id', 0) user_uuid = decoded_jwt.get('uuid', '') if user_id is None or user_id <= 0: raise exception.api.Unauthorized('请先登录') if user_uuid is None or user_uuid == '': raise exception.api.Unauthorized('请先登录') view.user_id = user_id view.user_uuid = user_uuid
def __init__(self, *args, **kwargs): # By default, we want a cache that can be shared across requests from different users ("public") # and a maximum age of 90 seconds, to keep our TTL low. # We bumped this from 60s -> 90s in November, 2016. self.cacheControl = app.config.get("CACHE_CONTROL", "public, max-age=90") self.log = logging.getLogger(self.__class__.__name__) MethodView.__init__(self, *args, **kwargs)
def __init__(self, *args, **kwargs): MethodView.__init__(self, *args, **kwargs) try: self.command_file = Model.Control.Command.find_command_file(config['nagios_main_cfg']) except Exception, err: abort(500, 'unable to locate command file: %s' % (str(err), ))
def __init__(self, *args, **kwargs): MethodView.__init__(self, *args, **kwargs) # Set the default representations self.representations = (current_labthing().representations if current_labthing() else DEFAULT_REPRESENTATIONS)
def __init__(self, *args, **kwargs): MethodView.__init__(self, *args, **kwargs) Model.cfg_file=config['nagios_main_cfg'] Model.pynag_directory=config['output_dir'] self.username = request.authorization.username self.endpoint = request.path.lstrip('/') self.endpoints = ApiEndpoints()
def __init__(self, *args, **kwargs): MethodView.__init__(self, *args, **kwargs) Model.cfg_file = config['nagios_main_cfg'] Model.pynag_directory = config['output_dir'] self.username = request.authorization.username self.endpoint = request.path.lstrip('/') self.endpoints = ApiEndpoints()
def __init__(self, *args, **kwargs): MethodView.__init__(self, *args, **kwargs) try: self.command_file = Control.Command.find_command_file( config['nagios_main_cfg']) except Exception as err: abort(500, 'unable to locate command file: %s' % (str(err), )) self.arguments = ['verify', 'restart', 'reload']
def __init__(self, *args, **kwargs): MethodView.__init__(self, *args, **kwargs) self.request = request try: self.controller = getattr( base, '{}{}'.format(str(self).replace('View', ''), 'Controller'))(request) except Exception as e: logger.error('{}{} does not exist'.format( str(self).replace('View', ''), 'Controller'))
def __init__(self, loader=None): Library.__init__(self) MethodView.__init__(self) self.__loader = loader self.__bridge_username = None self.log = None self.__queue = None self.__rooms = None self.__config = None self.__rooms_types = None self.__rooms = None self.config = None self.__bridge_username = None
def test_get_view_return(self): """ Test return value of _get_view method. """ view = self.flask_engine._get_view(MethodView) self.assertTrue(callable(view)) self.assertEqual(view.view_class, MethodView.as_view(MethodView.__name__).view_class)
def register_api(view: MethodView, endpoint: str, url: str, pk: str = 'id', pk_type: str = 'int'): """Add url rules for rest-api endpoint Args: view: view with get/post/put/delete methods endpoint: name of view url: endpoint url pk: primary key name pk_type: primary key type """ view_func = view.as_view(endpoint) bp.add_url_rule(url, defaults={pk: None}, view_func=view_func, methods=[ 'GET', ]) bp.add_url_rule(url, view_func=view_func, methods=[ 'POST', ]) bp.add_url_rule(f'{url}<{pk_type}:{pk}>', view_func=view_func, methods=['GET', 'PUT', 'DELETE'])
def __new__(cls, *args, **kwargs): """Class constructor, map api versions to view methods.""" with NEW_BASEVIEW_LOCK: cls.VERSION_TO_FETCHDATA = {} cls.VERSION_TO_RETURNDATA = {} cls.VERSION_TO_SWAGGERSPEC = {} for method_name, method in inspect.getmembers( cls, predicate=inspect_predicate): if hasattr(method, '_role'): if method._role == 'fetch': lookup = cls.VERSION_TO_FETCHDATA elif method._role == 'return': lookup = cls.VERSION_TO_RETURNDATA elif method._role == 'swagger': lookup = cls.VERSION_TO_SWAGGERSPEC else: raise ValueError('Unsupported method role: %r' % method._role) for version in method._versions or cls.SUPPORTED_VERSIONS: if version in lookup: raise ValueError( ('Could not register version {} to method {} ' 'in class {}, it has already been registered ' 'for role {} in method {}').format( version, method_name, cls.__name__, repr(method._role), lookup[version])) lookup[version] = method_name return MethodView.__new__(cls)
def dispatch_request(self, *args, **kwargs): key_value = kwargs.get(Command.PK) if key_value and not isinstance(key_value, int): return self.custom_func(key_value) if request.method not in self.ALLOWED_METHODS: self.not_allowed() if request.method in ['POST', 'PUT'] and self.FORM is None: raise UnprocessableEntity() return MethodView.dispatch_request(self, *args, **kwargs)
def base_rule(bp: object, api: MethodView): """Configure default routing for all endpoints.""" name = api.model.__tablename__ view = api.as_view(f"{name}_api") bp.add_url_rule(f'/{name}/', defaults={'id': None}, methods=['GET'], view_func=view) bp.add_url_rule(f'/{name}', methods=['POST'], view_func=view) bp.add_url_rule(f'/{name}/<int:id>', methods=['GET', 'PUT', 'DELETE'], view_func=view)
def __init__(self, loader = None): Library.__init__(self) MethodView.__init__(self) self.loader = loader self.log = None
def __init__(self): MethodView.__init__(self) self.config = CephApiConfig() self.clusterprop = CephClusterProperties(self.config)
def add_url_rule(self, rule: str, view: MethodView): self.__app.add_url_rule(rule, view_func=view.as_view(view.__qualname__))
def __init__(self, *args, **kwargs): MethodView.__init__(self, *args, **kwargs) self.retrieve_data()
def __init__(self): MethodView.__init__(self)
def __init__(self, *args, **kwargs): MethodView.__init__(self, *args, **kwargs)
def __init__(self, *args, **kwargs): MethodView.__init__(self, *args, **kwargs) self.config = Config(join(dirname(__file__), 'config.json')) self.state = TerraformState(self.config)
def __init__(self, *args, **kwargs): #self.auth = HTTPDigestAuth() MethodView.__init__(self, *args, **kwargs)
def __init__(self): MethodView.__init__(self) self.config = CephApiConfig()
def __init__(self): MethodView.__init__(self) self.config = current_app.config['USER_CONFIG']
def __init__(self): MethodView.__init__(self) self.config = current_app.config['USER_CONFIG'] self.clusterprop = CephClusterProperties(self.config)
def __init__(self, *args, **kwargs): self.log = logging.getLogger(self.__class__.__name__) MethodView.__init__(self, *args, **kwargs)
def __init__(self, *args, **kwargs): MethodView.__init__(self, *args, **kwargs) self.config = Config(join(dirname(dirname(__file__)), 'config.json')) self.state = TerraformState(self.config)
def __init__(self): MethodView.__init__(self) self.config = current_app.config['USER_CONFIG'] self.clusterprop = get_ceph_clusters().itervalues().next()