From 06a496f5ad19127986c7cc5ec4be021cc94c5dab Mon Sep 17 00:00:00 2001 From: pschu Date: Tue, 5 Dec 2023 11:31:23 +0100 Subject: [PATCH 1/3] fix prompt --- timer/token_timer.go | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/timer/token_timer.go b/timer/token_timer.go index 0096a44..c684301 100644 --- a/timer/token_timer.go +++ b/timer/token_timer.go @@ -87,18 +87,12 @@ func PromptString() { } func label(address string) string { + nonProd := os.Getenv("VAULTPAL_NP_URL") + prod := os.Getenv("VAULTPAL_PR_URL") switch address { - case "https://vault.x.sh": - return "[SB]" - case "https://vault.y.sh": - return "[NP]" - case "https://vault.x.run": - return "[PR]" - case "https://vault.security.aws.x.net": - return "[DSB]" - case "https://vault-p-np.security.aws.x.com": + case nonProd: return "N " - case "https://vault-p-pr.security.aws.x.com": + case prod: return "P " default: return "[??]" From 6e13bedf1bb5d27856c55b08f499537a699998e0 Mon Sep 17 00:00:00 2001 From: Till Kuhn Date: Mon, 11 Dec 2023 09:38:31 +0100 Subject: [PATCH 2/3] the return of the timer tests --- ...token-timer_test.go => token_timer_test.go} | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) rename timer/{token-timer_test.go => token_timer_test.go} (86%) diff --git a/timer/token-timer_test.go b/timer/token_timer_test.go similarity index 86% rename from timer/token-timer_test.go rename to timer/token_timer_test.go index 4a59837..a518e98 100644 --- a/timer/token-timer_test.go +++ b/timer/token_timer_test.go @@ -1,5 +1,23 @@ package timer +import ( + "github.com/stretchr/testify/assert" + "os" + "testing" +) + +func TestLabel(t *testing.T) { + _ = os.Setenv("VAULTPAL_NP_URL", "https://noprod") + _ = os.Setenv("VAULTPAL_PR_URL", "https://prod") + defer func() { + _ = os.Unsetenv("VAULTPAL_NP_URL") + _ = os.Unsetenv("VAULTPAL_PR_URL") + }() + assert.Equal(t, "N ", label("https://noprod")) + assert.Equal(t, "P ", label("https://prod")) + assert.Contains(t, label("https://nonsense"), "?") +} + // //import ( // "bytes" From 0dfff25ca918370aa5a348253ebecf9efa7d7902 Mon Sep 17 00:00:00 2001 From: Till Kuhn Date: Mon, 11 Dec 2023 09:56:33 +0100 Subject: [PATCH 3/3] add environment variables documention, refactor kubeconfig env key --- README.md | 12 ++++++++++-- kube/handler.go | 4 ++-- kube/handler_test.go | 4 ++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index b8f01c7..b943844 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ command call. Check the [releases](https://github.com/dbschenker/vaultpal/releases) section for the most recent binaries that are suitable for your operating system. -Please note that vaultpal has been thoroughly tested on MacOS (`*darwin` binaries) and Linux, but not on Windows. +Please note that vaultpal has been thoroughly tested on macOS (`*darwin` binaries) and Linux, but not on Windows. The binary should execute without issues, but there may be subtle differences, e.g. in the handling of file locations. Alternatively, consider [Windows Subsystem for Linux](https://docs.microsoft.com/de-de/windows/wsl/install-win10). @@ -182,7 +182,7 @@ with data: "server": "https://api.bibi.mytopic.com" } ``` -#### Cluster Alias +### Cluster Alias vaultpal supports the definition of an alias to a kubernetes cluster. This is useful if you want to use a generic endpoint like "int" or "prod" pointing to a cluster. @@ -200,6 +200,14 @@ with data: ``` Based on the alias value "bibi", vaultpal will read the configuration for cluster "bibi" in order to render the required certs and keys (pki). +### Environment Variables + +| Variable | Usage | +|--------------------------|----------------------------------------------------------------| +| VAULTPAL_NP_URL | URL of Vault production environment, used for prompt label | +| VAULTPAL_PR_URL | URL of Vault non-production environment, used for prompt label | +| VAULTPAL_KUBECONFIG_FILE | Custom location of kubeconfig file | + ## Contributing Pull requests are welcome. For major changes, please open an issue first to discuss your idea. diff --git a/kube/handler.go b/kube/handler.go index 738a8b5..0664bfe 100644 --- a/kube/handler.go +++ b/kube/handler.go @@ -14,7 +14,7 @@ import ( "strings" ) -const ENV_BRO_KUBECONFIG_FILE = "VBRO_KUBECONFIG_FILE" +const ENV_VAULTPAL_KUBECONFIG_FILE = "VAULTPAL_KUBECONFIG_FILE" func contextEntryMap(c []ContextEntry) map[string]ContextEntry { cm := map[string]ContextEntry{} @@ -246,7 +246,7 @@ func verifyPalKubeConfig(cluster config.KubeCluster) error { func ensurePalKubeConfigFile() (string, error) { kubeconfigFile := "" - if envPalKFile := os.Getenv(ENV_BRO_KUBECONFIG_FILE); envPalKFile == "" { + if envPalKFile := os.Getenv(ENV_VAULTPAL_KUBECONFIG_FILE); envPalKFile == "" { home, err := homedir.Dir() if err != nil { return "", err diff --git a/kube/handler_test.go b/kube/handler_test.go index e3acb72..f29c260 100644 --- a/kube/handler_test.go +++ b/kube/handler_test.go @@ -411,8 +411,8 @@ func TestWriteKubeconfigFile(t *testing.T) { defer os.RemoveAll(dir) os.Setenv(api.EnvVaultAddress, vm.Server.URL) os.Setenv(api.EnvVaultToken, "1234") - os.Setenv(ENV_BRO_KUBECONFIG_FILE, dir+"/bro_test_config") - broFile := os.Getenv(ENV_BRO_KUBECONFIG_FILE) + os.Setenv(ENV_VAULTPAL_KUBECONFIG_FILE, dir+"/bro_test_config") + broFile := os.Getenv(ENV_VAULTPAL_KUBECONFIG_FILE) err = os.Remove(broFile) if err != nil {