From 62bc41d615d079aaceec49553207ebc544b91600 Mon Sep 17 00:00:00 2001 From: Albin Kauffmann Date: Fri, 30 Jun 2023 10:11:32 +0200 Subject: [PATCH] feat(scw): export other SCW_* vars based on the selected profile This commit makes the `ssp` command also export the following variables: - SCW_DEFAULT_ORGANIZATION_ID - SCW_DEFAULT_PROJECT_ID - SCW_DEFAULT_REGION - SCW_DEFAULT_ZONE - SCW_API_URL - SCW_ACCESS_KEY (only exported if SCW_EXPORT_TOKENS set to "true") - SCW_SECRET_KEY (only exported if SCW_EXPORT_TOKENS set to "true") --- plugins/scw/scw.plugin.zsh | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/plugins/scw/scw.plugin.zsh b/plugins/scw/scw.plugin.zsh index 3edea2b12..346afefe0 100644 --- a/plugins/scw/scw.plugin.zsh +++ b/plugins/scw/scw.plugin.zsh @@ -10,7 +10,14 @@ function sgp() { # SCW profile selection function ssp() { if [[ -z "$1" ]]; then - unset SCW_PROFILE + unset SCW_PROFILE \ + SCW_DEFAULT_ORGANIZATION_ID \ + SCW_DEFAULT_PROJECT_ID \ + SCW_DEFAULT_REGION \ + SCW_DEFAULT_ZONE \ + SCW_API_URL \ + SCW_ACCESS_KEY \ + SCW_SECRET_KEY echo SCW profile cleared. return fi @@ -23,7 +30,33 @@ function ssp() { return 1 fi - export SCW_PROFILE=$1 + export SCW_PROFILE="$1" + unset SCW_DEFAULT_ORGANIZATION_ID \ + SCW_DEFAULT_PROJECT_ID \ + SCW_DEFAULT_REGION \ + SCW_DEFAULT_ZONE \ + SCW_API_URL \ + SCW_ACCESS_KEY \ + SCW_SECRET_KEY + + function scw_export() { + local -r scw_var="$1" + local -r scw_key="$2" + + local -r scw_val="$(scw config get $scw_key)" + if [[ -n "$scw_val" ]] && [[ "$scw_val" != "-" ]]; then + eval "export ${scw_var}=$scw_val" + fi + } + scw_export "SCW_DEFAULT_ORGANIZATION_ID" "default-organization-id" + scw_export "SCW_DEFAULT_PROJECT_ID" "default-project-id" + scw_export "SCW_DEFAULT_REGION" "default-region" + scw_export "SCW_DEFAULT_ZONE" "default-zone" + scw_export "SCW_API_URL" "api-url" + if [[ "$SCW_EXPORT_TOKENS" = "true" ]]; then + scw_export "SCW_ACCESS_KEY" "access-key" + scw_export "SCW_SECRET_KEY" "secret-key" + fi } function scw_profiles() {