Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nethsm: Add support for namespaces #535

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 49 additions & 2 deletions pynitrokey/cli/nethsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,15 @@ def get_user(ctx: Context, user_id: str) -> None:
help="The passphrase of the new user",
)
@click.option("-u", "--user-id", help="The user ID of the new user")
@click.option("-N", "--namespace", help="The namespace of the new user")
@click.pass_context
def add_user(
ctx: Context, real_name: str, role: str, passphrase: str, user_id: Optional[str]
ctx: Context,
real_name: str,
role: str,
passphrase: str,
user_id: Optional[str],
namespace: Optional[str],
) -> None:
"""Create a new user on the NetHSM.

Expand All @@ -310,7 +316,7 @@ def add_user(
role."""
with connect(ctx) as nethsm:
user_id = nethsm.add_user(
real_name, nethsm_sdk.Role.from_string(role), passphrase, user_id
real_name, nethsm_sdk.Role.from_string(role), passphrase, user_id, namespace
)
print(f"User {user_id} added to NetHSM {nethsm.host}")

Expand All @@ -328,6 +334,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(
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ dependencies = [
"protobuf >=3.17.3, < 4.0.0",
"click-aliases",
"semver",
"nethsm >= 1.1.0,<2",
"nethsm >=1.2.0, <2",
]
dynamic = ["version", "description"]

Expand Down