def cli(ctx: click.Context, verbose: int, umask: int, **kwargs) -> None: """ Interact with a Vault. See subcommands for details. All arguments can be passed by environment variables: VAULT_CLI_UPPERCASE_NAME (including VAULT_CLI_PASSWORD and VAULT_CLI_TOKEN). """ kwargs.pop("render") kwargs.pop("config_file") set_verbosity(verbose) set_umask(umask) assert ctx.default_map # make mypy happy kwargs.update(extract_special_args(ctx.default_map, os.environ)) # There might still be files to read, so let's do it now kwargs = settings.read_all_files(kwargs) saved_settings = kwargs.copy() saved_settings.update({"verbose": verbose, "umask": repr_octal(umask)}) ctx.obj = client.get_client_class()(**kwargs) # type: ignore ctx.obj.auth() ctx.obj.saved_settings = saved_settings
def test_read_all_files(tmpdir): token_path = str(tmpdir.join("token")) open(token_path, "wb").write(b"yay") password_path = str(tmpdir.join("password")) open(password_path, "wb").write(b"aaa") d = {"token_file": token_path, "password_file": password_path} expected = {"token": "yay", "password": "******"} assert settings.read_all_files(d) == expected
def cli(ctx: click.Context, **kwargs) -> None: """ Interact with a Vault. See subcommands for details. All arguments can be passed by environment variables: VAULT_CLI_UPPERCASE_NAME (including VAULT_CLI_PASSWORD and VAULT_CLI_TOKEN). """ kwargs.pop("config_file") verbose = kwargs.pop("verbose") backend: str = kwargs.pop("backend") kwargs.update(extract_special_args(ctx.default_map, os.environ)) # There might still be files to read, so let's do it now kwargs = settings.read_all_files(kwargs) saved_settings = kwargs.copy() saved_settings.update({"backend": backend, "verbose": verbose}) try: ctx.obj = client.get_client_from_kwargs(backend=backend, **kwargs) ctx.obj.saved_settings = saved_settings except ValueError as exc: raise click.UsageError(str(exc))
def test_read_all_files_no_file(): d = {"token": "yay", "password": "******"} assert settings.read_all_files(d) == d