Skip to content
Open
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
35 changes: 35 additions & 0 deletions oks_cli/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from nacl.public import PrivateKey, SealedBox
from nacl.encoding import Base64Encoder
from prettytable import TableStyle

from .utils import do_request, print_output, find_project_id_by_name, ctx_update, login_profile, profile_completer, project_completer, JSONClickException

Expand Down Expand Up @@ -166,4 +167,38 @@ def user_delete(ctx, project_name, user, output, dry_run, force, profile):
if force or click.confirm(f"Are you sure you want to delete the user '{user}'?", abort=True):
data = do_request("DELETE", f"projects/{project_id}/eim_users/{user}")
print_output(data, output)


@user.command('types', help="List available user types")
@click.option('--project-name', '-p', required=False, help="Project Name", shell_complete=project_completer)
@click.option('--output', '-o', type=click.Choice(["json", "yaml"]), help="Specify output format")
@click.option('--plain', is_flag=True, help="Plain table format")
@click.option('--profile', help="Configuration profile to use", shell_complete=profile_completer)
@click.pass_context
def user_types(ctx, project_name, output, plain, profile):
"""Display available user types."""
project_name, _, profile = ctx_update(ctx, project_name, None, profile)
login_profile(profile)

project_id = find_project_id_by_name(project_name)

data = do_request("GET", f'projects/{project_id}/eim_users/types')

if output:
print_output(data, output)
return

table = prettytable.PrettyTable()
table.field_names = ["USER TYPE", "DESCRIPTION"]

if plain:
table.set_style(TableStyle.PLAIN_COLUMNS)

for entry in data:
table.add_row([
entry.get("UserType", ""),
entry.get("Description") or "-"
])

click.echo(table)

2 changes: 2 additions & 0 deletions oks_cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ def find_response_object(data):
return response["EimUser"]
elif key == "Data":
return response
elif key == "EimUserTypes":
return response["EimUserTypes"]

raise click.ClickException("The API response format is incorrect.")

Expand Down
Loading