def test_load_from_envvar_no_default_config(swh_config, monkeypatch): config_path = str(swh_config) monkeypatch.setenv("SWH_CONFIG_FILENAME", config_path) actual_config = config.load_from_envvar() expected_config = config.read(config_path) assert actual_config == expected_config
def test_server_make_app_from_config_file(swh_storage_config): app = make_app_from_configfile() expected_cfg = load_from_envvar() assert app is not None assert isinstance(app, StorageServerApp) assert app.config["storage"] == expected_cfg["storage"] app2 = make_app_from_configfile() assert app is app2
def from_configfile(cls, **kwargs: Any): """Instantiate a lister from the configuration loaded from the SWH_CONFIG_FILENAME envvar, with potential extra keyword arguments if their value is not None. Args: kwargs: kwargs passed to the lister instantiation """ config = dict(load_from_envvar()) config.update({k: v for k, v in kwargs.items() if v is not None}) return cls.from_config(**config)
def from_configfile(cls, **kwargs: Any): """Instantiate a loader from the configuration loaded from the SWH_CONFIG_FILENAME envvar, with potential extra keyword arguments if their value is not None. Args: kwargs: kwargs passed to the loader instantiation """ config = dict(load_from_envvar(DEFAULT_CONFIG)) config.update({k: v for k, v in kwargs.items() if v is not None}) deposit_client = ApiClient(**config.pop("deposit")) return cls.from_config(deposit_client=deposit_client, **config)
def __init__(self) -> None: self.config = load_from_envvar(DEFAULT_CONFIG) self.storage = get_storage(**self.config["storage"]) self.objstorage = get_objstorage(**self.config["objstorage"]) self.compute_checksums = self.config["compute_checksums"] self.recompute_checksums = self.config["recompute_checksums"] self.batch_size_retrieve_content = self.config[ "batch_size_retrieve_content"] self.batch_size_update = self.config["batch_size_update"] self.log = logging.getLogger("swh.indexer.rehash") if not self.compute_checksums: raise ValueError("Checksums list should not be empty.")
def __init__(self): self.config: Dict[str, Any] = config.load_from_envvar(DEFAULT_CONFIG) self.scheduler: SchedulerInterface = get_scheduler( **self.config["scheduler"]) self.tool = { "name": "swh-deposit", "version": __version__, "configuration": { "sword_version": "2" }, } self.storage: StorageInterface = get_storage(**self.config["storage"]) self.storage_metadata: StorageInterface = get_storage( **self.config["storage_metadata"])
def __init__(self, config=None, **kw) -> None: """Prepare and check that the indexer is ready to run. """ super().__init__() if config is not None: self.config = config elif SWH_CONFIG: self.config = SWH_CONFIG.copy() else: self.config = load_from_envvar() self.config = merge_configs(DEFAULT_CONFIG, self.config) self.prepare() self.check() self.log.debug("%s: config=%s", self, self.config)
def test_load_from_envvar_with_default_config(swh_config, monkeypatch): default_config = { "number": 666, "something-cool": ["something", "cool"], } config_path = str(swh_config) monkeypatch.setenv("SWH_CONFIG_FILENAME", config_path) actual_config = config.load_from_envvar(default_config) expected_config = config.read(config_path) expected_config.update( {"number": 666, "something-cool": ["something", "cool"],} ) assert actual_config == expected_config
def __init__( self, config: Optional[Dict] = None, url: Optional[str] = None, auth: Optional[Tuple[str, str]] = None, ): if not url and not config: config = load_from_envvar() if config: url, auth = handle_deprecated_config(config) # needed to help mypy not be fooled by the Optional nature of url assert url is not None self.base_url = url.strip("/") + "/" self.auth = auth self.session = requests.Session() if auth: self.session.auth = auth self.session.headers.update( {"user-agent": f"swh-deposit/{swh_deposit_version}"})
def test_load_from_envvar_no_environment_var_swh_config_filename_set(): """Without SWH_CONFIG_FILENAME set, load_from_envvar raises""" with pytest.raises(AssertionError, match="SWH_CONFIG_FILENAME environment"): config.load_from_envvar()
def __init__(self): self.config: Dict[str, Any] = config.load_from_envvar() self.client = PrivateApiDepositClient(config=self.config["deposit"])