def cli_runner_env(monkeypatch): """As per cli_runner but uses environment variables""" # nexus_config is only used as an "easy" way to read configuration into a dictionary nexus_config = NexusConfig() nexus_config.load() config = {} for k, v in nexus_config.to_dict.items(): config[f'{constants.ENV_VAR_PREFIX}_{k.upper()}'] = v # TODO: any better spot to do this bool/str cast? config['NEXUS3_X509_VERIFY'] = str(config['NEXUS3_X509_VERIFY']) return CliRunner(env=config)
def get_client(): """ Returns a Nexus Client instance. Prints a warning if a configuration file isn't file. :rtype: nexuscli.nexus_client.NexusClient """ config = NexusConfig() try: config.load() except FileNotFoundError: sys.stderr.write( 'Warning: configuration not found; proceeding with defaults.\n' 'To remove this warning, please run `nexus3 login`\n') return NexusClient(config=config)
def test_write_config(config_args): """Ensure values written in config file can be read back""" nexus_config = NexusConfig(**config_args) nexus_config.dump() nexus_loaded_config = NexusConfig(config_path=config_args['config_path']) assert nexus_config.to_dict != nexus_loaded_config.to_dict nexus_loaded_config.load() assert nexus_config.to_dict == nexus_loaded_config.to_dict
def __init__(self, config=None): self.config = config or NexusConfig() self._local_sep = os.path.sep self._remote_sep = validations.REMOTE_PATH_SEPARATOR self._cleanup_policies = None self._repositories = None self._scripts = None self._verify = None self.repositories.refresh()
def test_nexus_context_path(url, expected_base, mocker): """ Check that the nexus context (URL prefix) is taken into account """ class MockResponse: def __init__(self): self.status_code = 200 def json(self): return '{}' mocker.patch('requests.request', return_value=MockResponse()) NexusClient(NexusConfig(url=url)) requests.request.assert_called_once_with( auth=(DEFAULTS['username'], DEFAULTS['password']), method='get', stream=True, url=(expected_base + 'service/rest/v1/repositories'), verify=True)
def get_client(): """ Returns a Nexus Client instance. Prints a warning if the configuration file doesn't exist. :rtype: nexuscli.nexus_client.NexusClient """ maybe_config = _get_client_kwargs() if maybe_config: config = NexusConfig(**_get_client_kwargs()) return NexusClient(config=config) config = NexusConfig() try: config.load() except FileNotFoundError: sys.stderr.write( 'Warning: configuration not found; proceeding with defaults.\n' 'To remove this warning, please run `nexus3 login`\n') return NexusClient(config=config)
def nexus_client(): config = NexusConfig() config.load() client = NexusClient(config=config) return client
def nexus_config(): config = NexusConfig() config.load() return config