Changeset View
Changeset View
Standalone View
Standalone View
swh/provenance/api/server.py
Show All 20 Lines | |||||
def get_global_provenance_storage() -> ProvenanceStorageInterface: | def get_global_provenance_storage() -> ProvenanceStorageInterface: | ||||
global storage | global storage | ||||
if storage is None: | if storage is None: | ||||
storage = get_provenance_storage(**app.config["provenance"]["storage"]) | storage = get_provenance_storage(**app.config["provenance"]["storage"]) | ||||
return storage | return storage | ||||
class ProvenanceStorageServerApp(RPCServerApp): | class ProvenanceStorageRPCServerApp(RPCServerApp): | ||||
extra_type_decoders = DECODERS | extra_type_decoders = DECODERS | ||||
extra_type_encoders = ENCODERS | extra_type_encoders = ENCODERS | ||||
app = ProvenanceStorageServerApp( | app = ProvenanceStorageRPCServerApp( | ||||
__name__, | __name__, | ||||
backend_class=ProvenanceStorageInterface, | backend_class=ProvenanceStorageInterface, | ||||
backend_factory=get_global_provenance_storage, | backend_factory=get_global_provenance_storage, | ||||
) | ) | ||||
def has_no_empty_params(rule: Rule) -> bool: | def has_no_empty_params(rule: Rule) -> bool: | ||||
return len(rule.defaults or ()) >= len(rule.arguments or ()) | return len(rule.defaults or ()) >= len(rule.arguments or ()) | ||||
▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | if type == "local": | ||||
raise KeyError("Invalid configuration; missing 'db' config entry") | raise KeyError("Invalid configuration; missing 'db' config entry") | ||||
return cfg | return cfg | ||||
api_cfg: Optional[Dict[str, Any]] = None | api_cfg: Optional[Dict[str, Any]] = None | ||||
def make_app_from_configfile() -> ProvenanceStorageServerApp: | def make_app_from_configfile() -> ProvenanceStorageRPCServerApp: | ||||
"""Run the WSGI app from the webserver, loading the configuration from | """Run the WSGI app from the webserver, loading the configuration from | ||||
a configuration file. | a configuration file. | ||||
SWH_CONFIG_FILENAME environment variable defines the | SWH_CONFIG_FILENAME environment variable defines the | ||||
configuration path to load. | configuration path to load. | ||||
""" | """ | ||||
global api_cfg | global api_cfg | ||||
if api_cfg is None: | if api_cfg is None: | ||||
config_path = os.environ.get("SWH_CONFIG_FILENAME") | config_path = os.environ.get("SWH_CONFIG_FILENAME") | ||||
api_cfg = load_and_check_config(config_path) | api_cfg = load_and_check_config(config_path) | ||||
app.config.update(api_cfg) | app.config.update(api_cfg) | ||||
handler = logging.StreamHandler() | handler = logging.StreamHandler() | ||||
app.logger.addHandler(handler) | app.logger.addHandler(handler) | ||||
return app | return app |