From 049f0df740cc422010abf4ee6034b7f7dd845bc0 Mon Sep 17 00:00:00 2001 From: Nick Cao Date: Thu, 20 Mar 2025 13:06:18 -0400 Subject: [PATCH 1/3] Use opt_duration_partial everywhere --- .../jumpstarter-cli-client/jumpstarter_cli_client/update.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/jumpstarter-cli-client/jumpstarter_cli_client/update.py b/packages/jumpstarter-cli-client/jumpstarter_cli_client/update.py index 9b899d268..0b3d13ffd 100644 --- a/packages/jumpstarter-cli-client/jumpstarter_cli_client/update.py +++ b/packages/jumpstarter-cli-client/jumpstarter_cli_client/update.py @@ -4,7 +4,7 @@ from jumpstarter_cli_common import OutputMode, OutputType, make_table, opt_output_all from jumpstarter_cli_common.exceptions import handle_exceptions -from .common import DURATION, opt_config +from .common import opt_config, opt_duration_partial @click.group() @@ -17,7 +17,7 @@ def update(): @update.command(name="lease") @opt_config @click.argument("name") -@click.option("--duration", "duration", type=DURATION, required=True) +@opt_duration_partial(required=True) @opt_output_all @handle_exceptions async def update_lease(config, name: str, duration: timedelta, output: OutputType): From 4d00a88d9ad9521d355d0fa1860fbc059ce7a011 Mon Sep 17 00:00:00 2001 From: Nick Cao Date: Thu, 20 Mar 2025 13:07:25 -0400 Subject: [PATCH 2/3] Fully featured selector is now supported everywhere --- .../jumpstarter_cli_client/client_shell.py | 4 ++-- .../jumpstarter_cli_client/common.py | 8 -------- .../jumpstarter_cli_client/create.py | 4 ++-- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/packages/jumpstarter-cli-client/jumpstarter_cli_client/client_shell.py b/packages/jumpstarter-cli-client/jumpstarter_cli_client/client_shell.py index 04236163b..2bd77df69 100644 --- a/packages/jumpstarter-cli-client/jumpstarter_cli_client/client_shell.py +++ b/packages/jumpstarter-cli-client/jumpstarter_cli_client/client_shell.py @@ -4,14 +4,14 @@ import asyncclick as click from jumpstarter_cli_common.exceptions import handle_exceptions -from .common import opt_config, opt_duration_partial, opt_selector_simple +from .common import opt_config, opt_duration_partial, opt_selector from jumpstarter.common.utils import launch_shell @click.command("shell", short_help="Spawns a shell connecting to a leased remote exporter") @click.option("-n", "--lease", "lease_name", type=str) @opt_config -@opt_selector_simple +@opt_selector @opt_duration_partial(default=timedelta(minutes=30), show_default="00:30:00") @handle_exceptions def client_shell(config, selector: str, duration: timedelta, lease_name): diff --git a/packages/jumpstarter-cli-client/jumpstarter_cli_client/common.py b/packages/jumpstarter-cli-client/jumpstarter_cli_client/common.py index 978cbfc6c..685328051 100644 --- a/packages/jumpstarter-cli-client/jumpstarter_cli_client/common.py +++ b/packages/jumpstarter-cli-client/jumpstarter_cli_client/common.py @@ -16,14 +16,6 @@ " Matching objects must satisfy all of the specified label constraints.", ) -opt_selector_simple = click.option( - "-l", - "--selector", - help="Selector (label query) to filter on, only supports '=', (e.g. -l key1=value1,key2=value2)." - " Matching objects must satisfy all of the specified label constraints.", - required=True, -) - class ClientParamType(click.ParamType): name = "client" diff --git a/packages/jumpstarter-cli-client/jumpstarter_cli_client/create.py b/packages/jumpstarter-cli-client/jumpstarter_cli_client/create.py index 66458cde1..2b3656222 100644 --- a/packages/jumpstarter-cli-client/jumpstarter_cli_client/create.py +++ b/packages/jumpstarter-cli-client/jumpstarter_cli_client/create.py @@ -9,7 +9,7 @@ ) from jumpstarter_cli_common.exceptions import handle_exceptions -from .common import opt_config, opt_duration_partial, opt_selector_simple +from .common import opt_config, opt_duration_partial, opt_selector @click.group() @@ -21,7 +21,7 @@ def create(): @create.command(name="lease") @opt_config -@opt_selector_simple +@opt_selector @opt_duration_partial(required=True) @opt_output_all @handle_exceptions From 86ddbbc3228b8f5b129925a9970f465890aac723 Mon Sep 17 00:00:00 2001 From: Nick Cao Date: Thu, 20 Mar 2025 13:13:13 -0400 Subject: [PATCH 3/3] Dedup oidc related options --- .../jumpstarter_cli_client/client_login.py | 14 ++------------ .../jumpstarter_cli_common/oidc.py | 17 +++++++++++++---- .../jumpstarter_cli_exporter/exporter_login.py | 9 ++------- 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/packages/jumpstarter-cli-client/jumpstarter_cli_client/client_login.py b/packages/jumpstarter-cli-client/jumpstarter_cli_client/client_login.py index f54fae3a1..00c64b2a2 100644 --- a/packages/jumpstarter-cli-client/jumpstarter_cli_client/client_login.py +++ b/packages/jumpstarter-cli-client/jumpstarter_cli_client/client_login.py @@ -1,6 +1,6 @@ import asyncclick as click from jumpstarter_cli_common.exceptions import async_handle_exceptions -from jumpstarter_cli_common.oidc import Config, decode_jwt_issuer, opt_client_id, opt_connector_id +from jumpstarter_cli_common.oidc import Config, decode_jwt_issuer, opt_oidc from jumpstarter.common.exceptions import FileNotFoundError from jumpstarter.config import ClientConfigV1Alpha1, ClientConfigV1Alpha1Drivers, ObjectMeta, UserConfigV1Alpha1 @@ -27,15 +27,6 @@ help="Enter the Jumpstarter client name.", default=None, ) -@click.option("--username", type=str, help="Enter the OIDC username.", default=None) -@click.option("--password", type=str, help="Enter the OIDC password.", default=None) -@click.option("--token", type=str, help="Enter the OIDC token.", default=None) -@click.option( - "--issuer", - type=str, - help="Enter the OIDC issuer.", - default=None, -) @click.option( "--allow", type=str, @@ -45,8 +36,7 @@ @click.option( "--unsafe", is_flag=True, help="Should all driver client packages be allowed to load (UNSAFE!).", default=None ) -@opt_client_id -@opt_connector_id +@opt_oidc @async_handle_exceptions async def client_login( # noqa: C901 alias: str, diff --git a/packages/jumpstarter-cli-common/jumpstarter_cli_common/oidc.py b/packages/jumpstarter-cli-common/jumpstarter_cli_common/oidc.py index 85f5671d7..8e89e821f 100644 --- a/packages/jumpstarter-cli-common/jumpstarter_cli_common/oidc.py +++ b/packages/jumpstarter-cli-common/jumpstarter_cli_common/oidc.py @@ -1,6 +1,7 @@ import json import os from dataclasses import dataclass +from functools import wraps from typing import ClassVar import aiohttp @@ -21,10 +22,18 @@ truststore.inject_into_ssl() -opt_client_id = click.option("--client-id", "client_id", type=str, default="jumpstarter-cli", help="OIDC client id") -opt_connector_id = click.option( - "--connector-id", "connector_id", type=str, help="OIDC token exchange connector id (Dex specific)" -) +def opt_oidc(f): + @click.option("--issuer", help="OIDC issuer") + @click.option("--client-id", "client_id", help="OIDC client id", default="jumpstarter-cli") + @click.option("--token", help="OIDC access token") + @click.option("--username", help="OIDC username") + @click.option("--password", help="OIDC password") + @click.option("--connector-id", "connector_id", help="OIDC token exchange connector id (Dex specific)") + @wraps(f) + def wrapper(*args, **kwds): + return f(*args, **kwds) + + return wrapper @dataclass(kw_only=True) diff --git a/packages/jumpstarter-cli-exporter/jumpstarter_cli_exporter/exporter_login.py b/packages/jumpstarter-cli-exporter/jumpstarter_cli_exporter/exporter_login.py index ea788c171..8d7801be8 100644 --- a/packages/jumpstarter-cli-exporter/jumpstarter_cli_exporter/exporter_login.py +++ b/packages/jumpstarter-cli-exporter/jumpstarter_cli_exporter/exporter_login.py @@ -1,5 +1,5 @@ import asyncclick as click -from jumpstarter_cli_common.oidc import Config, decode_jwt_issuer, opt_client_id, opt_connector_id +from jumpstarter_cli_common.oidc import Config, decode_jwt_issuer, opt_oidc from jumpstarter.config.exporter import ExporterConfigV1Alpha1, ObjectMeta @@ -9,12 +9,7 @@ @click.option("-e", "--endpoint", type=str, help="Enter the Jumpstarter service endpoint.", default=None) @click.option("--namespace", type=str, help="Enter the Jumpstarter exporter namespace.", default=None) @click.option("--name", type=str, help="Enter the Jumpstarter exporter name.", default=None) -@click.option("--username", type=str, help="Enter the OIDC username.", default=None) -@click.option("--password", type=str, help="Enter the OIDC password.", default=None) -@click.option("--token", type=str, help="Enter the OIDC token.", default=None) -@click.option("--issuer", type=str, help="Enter the OIDC issuer.", default=None) -@opt_client_id -@opt_connector_id +@opt_oidc async def exporter_login( alias: str, endpoint: str,