From e2383b84f88e0e7d35f6a3a846b54c69e3bee6ee Mon Sep 17 00:00:00 2001 From: aszlig Date: Tue, 12 Apr 2016 05:38:37 +0200 Subject: [PATCH] nixos/taskserver/helper: Improve CLI subcommands Try to match the subcommands to act more like the subcommands from the taskd binary and also add a subcommand to list groups. Signed-off-by: aszlig --- .../services/misc/taskserver/helper-tool.py | 55 +++++++++++++++---- nixos/tests/taskserver.nix | 20 +++---- 2 files changed, 55 insertions(+), 20 deletions(-) diff --git a/nixos/modules/services/misc/taskserver/helper-tool.py b/nixos/modules/services/misc/taskserver/helper-tool.py index e2c340fbd2a0..f5d3c2ecbd37 100644 --- a/nixos/modules/services/misc/taskserver/helper-tool.py +++ b/nixos/modules/services/misc/taskserver/helper-tool.py @@ -441,7 +441,31 @@ def cli(ctx): ctx.fail(msg.format(path)) -@cli.command("list-users") +@cli.group("org") +def org_cli(): + """ + Manage organisations + """ + pass + + +@cli.group("user") +def user_cli(): + """ + Manage users + """ + pass + + +@cli.group("group") +def group_cli(): + """ + Manage groups + """ + pass + + +@user_cli.command("list") @click.argument("organisation", type=ORGANISATION) def list_users(organisation): """ @@ -452,7 +476,18 @@ def list_users(organisation): sys.stdout.write(user.name + "\n") -@cli.command("list-orgs") +@group_cli.command("list") +@click.argument("organisation", type=ORGANISATION) +def list_groups(organisation): + """ + List all users belonging to the specified organisation. + """ + label("The following users exists for {}:".format(organisation.name)) + for group in organisation.groups.values(): + sys.stdout.write(group.name + "\n") + + +@org_cli.command("list") def list_orgs(): """ List available organisations @@ -462,7 +497,7 @@ def list_orgs(): sys.stdout.write(org.name + "\n") -@cli.command("get-uuid") +@user_cli.command("getkey") @click.argument("organisation", type=ORGANISATION) @click.argument("user") def get_uuid(organisation, user): @@ -478,7 +513,7 @@ def get_uuid(organisation, user): sys.stdout.write(user.key + "\n") -@cli.command("export-user") +@user_cli.command("export") @click.argument("organisation", type=ORGANISATION) @click.argument("user") def export_user(organisation, user): @@ -496,7 +531,7 @@ def export_user(organisation, user): sys.stdout.write(userobj.export()) -@cli.command("add-org") +@org_cli.command("add") @click.argument("name") def add_org(name): """ @@ -510,7 +545,7 @@ def add_org(name): mark_imperative(name) -@cli.command("del-org") +@org_cli.command("remove") @click.argument("name") def del_org(name): """ @@ -526,7 +561,7 @@ def del_org(name): click.echo(msg.format(name), err=True) -@cli.command("add-user") +@user_cli.command("add") @click.argument("organisation", type=ORGANISATION) @click.argument("user") def add_user(organisation, user): @@ -545,7 +580,7 @@ def add_user(organisation, user): mark_imperative(organisation.name, "users", userobj.key) -@cli.command("del-user") +@user_cli.command("remove") @click.argument("organisation", type=ORGANISATION) @click.argument("user") def del_user(organisation, user): @@ -561,7 +596,7 @@ def del_user(organisation, user): click.echo(msg.format(user), err=True) -@cli.command("add-group") +@group_cli.command("add") @click.argument("organisation", type=ORGANISATION) @click.argument("group") def add_group(organisation, group): @@ -576,7 +611,7 @@ def add_group(organisation, group): mark_imperative(organisation.name, "groups", groupobj.name) -@cli.command("del-group") +@group_cli.command("remove") @click.argument("organisation", type=ORGANISATION) @click.argument("group") def del_group(organisation, group): diff --git a/nixos/tests/taskserver.nix b/nixos/tests/taskserver.nix index 0521f97431b3..d770b20a7757 100644 --- a/nixos/tests/taskserver.nix +++ b/nixos/tests/taskserver.nix @@ -44,7 +44,7 @@ import ./make-test.nix { ); my $exportinfo = $server->succeed( - "nixos-taskserver export-user $org $user" + "nixos-taskserver user export $org $user" ); $exportinfo =~ s/'/'\\'''/g; @@ -74,10 +74,10 @@ import ./make-test.nix { sub readdImperativeUser { $server->nest("(re-)add imperative user bar", sub { - $server->execute("nixos-taskserver del-org imperativeOrg"); + $server->execute("nixos-taskserver org remove imperativeOrg"); $server->succeed( - "nixos-taskserver add-org imperativeOrg", - "nixos-taskserver add-user imperativeOrg bar" + "nixos-taskserver org add imperativeOrg", + "nixos-taskserver user add imperativeOrg bar" ); setupClientsFor "imperativeOrg", "bar"; }); @@ -109,9 +109,9 @@ import ./make-test.nix { $server->waitForUnit("taskserver.service"); $server->succeed( - "nixos-taskserver list-users testOrganisation | grep -qxF alice", - "nixos-taskserver list-users testOrganisation | grep -qxF foo", - "nixos-taskserver list-users anotherOrganisation | grep -qxF bob" + "nixos-taskserver user list testOrganisation | grep -qxF alice", + "nixos-taskserver user list testOrganisation | grep -qxF foo", + "nixos-taskserver user list anotherOrganisation | grep -qxF bob" ); $server->waitForOpenPort(${portStr}); @@ -125,7 +125,7 @@ import ./make-test.nix { testSync $_ for ("alice", "bob", "foo"); - $server->fail("nixos-taskserver add-user imperativeOrg bar"); + $server->fail("nixos-taskserver user add imperativeOrg bar"); readdImperativeUser; testSync "bar"; @@ -133,7 +133,7 @@ import ./make-test.nix { subtest "checking certificate revocation of user bar", sub { $client1->succeed(checkClientCert "bar"); - $server->succeed("nixos-taskserver del-user imperativeOrg bar"); + $server->succeed("nixos-taskserver user remove imperativeOrg bar"); restartServer; $client1->fail(checkClientCert "bar"); @@ -147,7 +147,7 @@ import ./make-test.nix { subtest "checking certificate revocation of org imperativeOrg", sub { $client1->succeed(checkClientCert "bar"); - $server->succeed("nixos-taskserver del-org imperativeOrg"); + $server->succeed("nixos-taskserver org remove imperativeOrg"); restartServer; $client1->fail(checkClientCert "bar");