From d6f64ad72de0855daecb63206e4e5e8216465a8a Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Thu, 16 May 2024 21:37:21 +0200 Subject: [PATCH] fixup! nethsm: Add support for namespaces --- pynitrokey/cli/nethsm.py | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/pynitrokey/cli/nethsm.py b/pynitrokey/cli/nethsm.py index 2a8d1eff..8bec17e4 100644 --- a/pynitrokey/cli/nethsm.py +++ b/pynitrokey/cli/nethsm.py @@ -333,6 +333,47 @@ def delete_user(ctx: Context, user_id: str) -> None: print(f"User {user_id} deleted on NetHSM {nethsm.host}") +@nethsm.command() +@click.pass_context +def list_namespaces(ctx: Context) -> None: + """List all namespaces on the NetHSM. + + This command requires authentication as a user with the Administrator + role.""" + with connect(ctx) as nethsm: + namespaces = nethsm.list_namespaces() + + print(f"Namespaces on NetHSM {nethsm.host}:") + for namespace in namespaces: + print(f"- {namespace}") + + +@nethsm.command() +@click.argument("namespace") +@click.pass_context +def add_namespace(ctx: Context, namespace: str) -> None: + """Add a new namespace on the NetHSM. + + This command requires authentication as a user with the Administrator + role.""" + with connect(ctx) as nethsm: + nethsm.add_namespace(namespace) + print(f"Namespace {namespace} added to NetHSM {nethsm.host}") + + +@nethsm.command() +@click.argument("namespace") +@click.pass_context +def delete_namespace(ctx: Context, namespace: str) -> None: + """Delete a namespace on the NetHSM. + + This command requires authentication as a user with the Administrator + role.""" + with connect(ctx) as nethsm: + nethsm.delete_namespace(namespace) + print(f"Namespace {namespace} deleted on NetHSM {nethsm.host}") + + @nethsm.command() @click.option("-u", "--user-id", help="The user ID of the user") @click.option(