swh.storage.api.server module#
- class swh.storage.api.server.StorageServerApp(*args, backend_class=None, backend_factory=None, **kwargs)[source]#
Bases:
RPCServerApp
- extra_type_decoders: Dict[str, Callable] = {'branch_by_name_response': <function _decode_snapshot_branch_by_name_response>, 'core_swhid': <bound method _BaseSWHID.from_string of <class 'swh.model.swhids.CoreSWHID'>>, 'extended_swhid': <bound method _BaseSWHID.from_string of <class 'swh.model.swhids.ExtendedSWHID'>>, 'identifiers_enum': <function _decode_swhids_enum>, 'model': <function <lambda>>, 'model_enum': <function _decode_model_enum>, 'object_reference': <function _decode_object_reference>, 'origin_visit_with_statuses': <function _decode_origin_visit_with_statuses>, 'qualified_swhid': <bound method QualifiedSWHID.from_string of <class 'swh.model.swhids.QualifiedSWHID'>>, 'storage_enum': <function _decode_storage_enum>, 'swhids_enum': <function _decode_swhids_enum>}#
Value of extra_decoders passed to json_loads or msgpack_loads to be able to deserialize more object types.
- extra_type_encoders: List[Tuple[type, str, Callable]] = [(<class 'swh.model.model.BaseModel'>, 'model', <function _encode_model_object>), (<class 'swh.model.swhids.CoreSWHID'>, 'core_swhid', <class 'str'>), (<class 'swh.model.swhids.ExtendedSWHID'>, 'extended_swhid', <class 'str'>), (<class 'swh.model.swhids.QualifiedSWHID'>, 'qualified_swhid', <class 'str'>), (<enum 'ObjectType'>, 'identifiers_enum', <function _encode_enum>), (<enum 'MetadataAuthorityType'>, 'model_enum', <function _encode_enum>), (<enum 'ListOrder'>, 'storage_enum', <function _encode_enum>), (<class 'swh.storage.interface.OriginVisitWithStatuses'>, 'origin_visit_with_statuses', <function _encode_origin_visit_with_statuses>), (<class 'swh.storage.interface.ObjectReference'>, 'object_reference', <function _encode_object_reference>), (<class 'swh.storage.interface.SnapshotBranchByNameResponse'>, 'branch_by_name_response', <function _encode_snapshot_branch_by_name_response>)]#
Value of extra_encoders passed to json_dumps or msgpack_dumps to be able to serialize more object types.
- method_decorators: List[Callable[[Callable], Callable]] = [<function timed>]#
List of decorators to all methods generated from the
backend_class
.
- json: JSONProvider#
Provides access to JSON methods. Functions in
flask.json
will call methods on this provider when the application context is active. Used for handling JSON requests and responses.An instance of
json_provider_class
. Can be customized by changing that attribute on a subclass, or by assigning to this attribute afterwards.The default,
DefaultJSONProvider
, uses Python’s built-injson
library. A different provider can use a different JSON library.New in version 2.2.
- url_build_error_handlers: t.List[t.Callable[[Exception, str, t.Dict[str, t.Any]], str]]#
A list of functions that are called by
handle_url_build_error()
whenurl_for()
raises aBuildError
. Each function is called witherror
,endpoint
andvalues
. If a function returnsNone
or raises aBuildError
, it is skipped. Otherwise, its return value is returned byurl_for
.New in version 0.9.
- before_first_request_funcs: t.List[ft.BeforeFirstRequestCallable]#
A list of functions that will be called at the beginning of the first request to this instance. To register a function, use the
before_first_request()
decorator.Deprecated since version 2.2: Will be removed in Flask 2.3. Run setup code when creating the application instead.
New in version 0.8.
- teardown_appcontext_funcs: t.List[ft.TeardownCallable]#
A list of functions that are called when the application context is destroyed. Since the application context is also torn down if the request ends this is the place to store code that disconnects from databases.
New in version 0.9.
- shell_context_processors: t.List[ft.ShellContextProcessorCallable]#
A list of shell context processor functions that should be run when a shell context is created.
New in version 0.11.
- blueprints: t.Dict[str, 'Blueprint']#
Maps registered blueprint names to blueprint objects. The dict retains the order the blueprints were registered in. Blueprints can be registered multiple times, this dict does not track how often they were attached.
New in version 0.7.
- extensions: dict#
a place where extensions can store application specific state. For example this is where an extension could store database engines and similar things.
The key must match the name of the extension module. For example in case of a “Flask-Foo” extension in flask_foo, the key would be
'foo'
.New in version 0.7.
- view_functions: t.Dict[str, t.Callable]#
A dictionary mapping endpoint names to view functions.
To register a view function, use the
route()
decorator.This data structure is internal. It should not be modified directly and its format may change at any time.
- error_handler_spec: t.Dict[ft.AppOrBlueprintKey, t.Dict[t.Optional[int], t.Dict[t.Type[Exception], ft.ErrorHandlerCallable]]]#
A data structure of registered error handlers, in the format
{scope: {code: {class: handler}}}
. Thescope
key is the name of a blueprint the handlers are active for, orNone
for all requests. Thecode
key is the HTTP status code forHTTPException
, orNone
for other exceptions. The innermost dictionary maps exception classes to handler functions.To register an error handler, use the
errorhandler()
decorator.This data structure is internal. It should not be modified directly and its format may change at any time.
- before_request_funcs: t.Dict[ft.AppOrBlueprintKey, t.List[ft.BeforeRequestCallable]]#
A data structure of functions to call at the beginning of each request, in the format
{scope: [functions]}
. Thescope
key is the name of a blueprint the functions are active for, orNone
for all requests.To register a function, use the
before_request()
decorator.This data structure is internal. It should not be modified directly and its format may change at any time.
- after_request_funcs: t.Dict[ft.AppOrBlueprintKey, t.List[ft.AfterRequestCallable]]#
A data structure of functions to call at the end of each request, in the format
{scope: [functions]}
. Thescope
key is the name of a blueprint the functions are active for, orNone
for all requests.To register a function, use the
after_request()
decorator.This data structure is internal. It should not be modified directly and its format may change at any time.
- teardown_request_funcs: t.Dict[ft.AppOrBlueprintKey, t.List[ft.TeardownCallable]]#
A data structure of functions to call at the end of each request even if an exception is raised, in the format
{scope: [functions]}
. Thescope
key is the name of a blueprint the functions are active for, orNone
for all requests.To register a function, use the
teardown_request()
decorator.This data structure is internal. It should not be modified directly and its format may change at any time.
- template_context_processors: t.Dict[ft.AppOrBlueprintKey, t.List[ft.TemplateContextProcessorCallable]]#
A data structure of functions to call to pass extra context values when rendering templates, in the format
{scope: [functions]}
. Thescope
key is the name of a blueprint the functions are active for, orNone
for all requests.To register a function, use the
context_processor()
decorator.This data structure is internal. It should not be modified directly and its format may change at any time.
- url_value_preprocessors: t.Dict[ft.AppOrBlueprintKey, t.List[ft.URLValuePreprocessorCallable]]#
A data structure of functions to call to modify the keyword arguments passed to the view function, in the format
{scope: [functions]}
. Thescope
key is the name of a blueprint the functions are active for, orNone
for all requests.To register a function, use the
url_value_preprocessor()
decorator.This data structure is internal. It should not be modified directly and its format may change at any time.
- url_default_functions: t.Dict[ft.AppOrBlueprintKey, t.List[ft.URLDefaultCallable]]#
A data structure of functions to call to modify the keyword arguments when generating URLs, in the format
{scope: [functions]}
. Thescope
key is the name of a blueprint the functions are active for, orNone
for all requests.To register a function, use the
url_defaults()
decorator.This data structure is internal. It should not be modified directly and its format may change at any time.
- swh.storage.api.server.load_and_check_config(config_path: Optional[str]) Dict[str, Any] [source]#
- Check the minimal configuration is set to run the api or raise an
error explanation.
- Parameters:
config_path – Path to the configuration file to load
- Raises:
Error if the setup is not as expected –
- Returns:
configuration as a dict
- swh.storage.api.server.make_app_from_configfile() StorageServerApp [source]#
Run the WSGI app from the webserver, loading the configuration from a configuration file.
SWH_CONFIG_FILENAME environment variable defines the configuration path to load.