Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix shell prompt #47

Merged
merged 3 commits into from
Dec 19, 2023
Merged
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
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions kube/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions kube/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 4 additions & 10 deletions timer/token_timer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 "[??]"
Expand Down
18 changes: 18 additions & 0 deletions timer/token-timer_test.go → timer/token_timer_test.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Loading