From 1ce93e3951673a1e848d279c927631b8ad5dafa9 Mon Sep 17 00:00:00 2001 From: Emmanuel Quevillon Date: Fri, 8 Aug 2025 16:28:29 +0200 Subject: [PATCH 1/3] :sparkle: feat: Support OKS_PROFILE environment variable User can set OKS_PROFILE envrionment variable as default profile when running any oks-cli command without the need to set --profile option --- oks_cli/utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/oks_cli/utils.py b/oks_cli/utils.py index fd068f3..64feb1a 100644 --- a/oks_cli/utils.py +++ b/oks_cli/utils.py @@ -309,8 +309,13 @@ def login_profile(name): Raises an exception if the profile does not exist or lacks required info. """ _, PROFILE_FILE = get_config_path() + + # check is profile name is defined by user as environment variable if name is None: - name = "default" + if os.getenv('OKS_PROFILE') is None: + name = "default" + else: + name = os.getenv('OKS_PROFILE') if os.path.exists(PROFILE_FILE): with open(PROFILE_FILE, 'r') as file: From 8f7a890ea7572972e36ac4568df2bd98eba42eb6 Mon Sep 17 00:00:00 2001 From: Emmanuel Quevillon Date: Mon, 18 Aug 2025 16:01:27 +0200 Subject: [PATCH 2/3] :bug: fix: Use OKS_PROFILE while using command completion for cluster sub-command group --- oks_cli/utils.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/oks_cli/utils.py b/oks_cli/utils.py index 64feb1a..599d33c 100644 --- a/oks_cli/utils.py +++ b/oks_cli/utils.py @@ -641,7 +641,14 @@ def shell_completions(ctx, param: click.core.Option, incomplete): CONFIG_FOLDER, _ = get_config_path() profiles = profile_list() - profile = ctx.params["profile"] or ctx.parent.params["profile"] or ctx.parent.parent.params["profile"] or "default" + profile = ctx.params["profile"] or ctx.parent.params["profile"] or ctx.parent.parent.params["profile"] or None + + # Check if OKS_PROFILE is set somehow + if profile is None: + if os.getenv('OKS_PROFILE') is None: + profile = 'default' + else: + profile = os.getenv('OKS_PROFILE') if profile not in profiles: return [] @@ -827,6 +834,7 @@ def ctx_update(ctx, project_name=None, cluster_name=None, profile=None, overwrit raise click.BadParameter("profile already set before") ctx.obj['profile'] = profile + print("[ctx_update] Profile={}".format(ctx.obj.get('profile')), file=sys.stderr) return (ctx.obj.get('project_name'), ctx.obj.get('cluster_name'), ctx.obj.get('profile')) def get_project_name(project_name): From f9264a2ab55429e85954f092c5c00bd8014d8d5c Mon Sep 17 00:00:00 2001 From: Emmanuel Quevillon Date: Mon, 18 Aug 2025 16:22:35 +0200 Subject: [PATCH 3/3] :bug: fix: remove debug line --- oks_cli/utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/oks_cli/utils.py b/oks_cli/utils.py index 599d33c..6f181ee 100644 --- a/oks_cli/utils.py +++ b/oks_cli/utils.py @@ -834,7 +834,6 @@ def ctx_update(ctx, project_name=None, cluster_name=None, profile=None, overwrit raise click.BadParameter("profile already set before") ctx.obj['profile'] = profile - print("[ctx_update] Profile={}".format(ctx.obj.get('profile')), file=sys.stderr) return (ctx.obj.get('project_name'), ctx.obj.get('cluster_name'), ctx.obj.get('profile')) def get_project_name(project_name):