Merge pull request 'improve error message if users don't exist' (#108) from Mic92-mic92 into main
All checks were successful
build / test (push) Successful in 21s
All checks were successful
build / test (push) Successful in 21s
This commit is contained in:
commit
eeb272d8b0
@ -108,12 +108,23 @@ def groups_folder(group: str) -> Path:
|
||||
return sops_secrets_folder() / group / "groups"
|
||||
|
||||
|
||||
def list_directory(directory: Path) -> str:
|
||||
if not directory.exists():
|
||||
return "{directory} does not exist"
|
||||
msg = f"\n{directory} contains:"
|
||||
for f in directory.iterdir():
|
||||
msg += f"\n {f.name}"
|
||||
return msg
|
||||
|
||||
|
||||
def allow_member(
|
||||
group_folder: Path, source_folder: Path, name: str, do_update_keys: bool = True
|
||||
) -> None:
|
||||
source = source_folder / name
|
||||
if not source.exists():
|
||||
raise ClanError(f"{name} does not exist in {source_folder}")
|
||||
msg = f"{name} does not exist in {source_folder}"
|
||||
msg += list_directory(source_folder)
|
||||
raise ClanError(msg)
|
||||
group_folder.mkdir(parents=True, exist_ok=True)
|
||||
user_target = group_folder / name
|
||||
if user_target.exists():
|
||||
@ -134,7 +145,9 @@ def allow_member(
|
||||
def disallow_member(group_folder: Path, name: str) -> None:
|
||||
target = group_folder / name
|
||||
if not target.exists():
|
||||
raise ClanError(f"{name} does not exist in group in {group_folder}")
|
||||
msg = f"{name} does not exist in group in {group_folder}"
|
||||
msg += list_directory(group_folder)
|
||||
raise ClanError(msg)
|
||||
|
||||
keys = collect_keys_for_path(group_folder.parent)
|
||||
|
||||
|
@ -79,7 +79,7 @@ python3.pkgs.buildPythonPackage {
|
||||
'';
|
||||
checkPhase = ''
|
||||
PYTHONPATH= $out/bin/clan --help
|
||||
if grep --include \*.py -q "breakpoint()" $out; then
|
||||
if grep --include \*.py -Rq "breakpoint()" $out; then
|
||||
echo "breakpoint() found in $out:"
|
||||
grep --include \*.py -Rn "breakpoint()" $out
|
||||
exit 1
|
||||
|
@ -128,7 +128,7 @@ def test_secrets(
|
||||
cli.run(["machines", "add", "machine1", test_keys[0].pubkey])
|
||||
cli.run(["machines", "add-secret", "machine1", "key"])
|
||||
|
||||
with mock_env(SOPS_AGE_KEY=test_keys[1].privkey, SOPS_AGE_KEY_FILE=""):
|
||||
with mock_env(SOPS_AGE_KEY=test_keys[0].privkey, SOPS_AGE_KEY_FILE=""):
|
||||
capsys.readouterr()
|
||||
cli.run(["get", "key"])
|
||||
assert capsys.readouterr().out == "foo"
|
||||
|
Loading…
Reference in New Issue
Block a user