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 #7 #8

Merged
merged 2 commits into from
Jun 10, 2024
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
5 changes: 5 additions & 0 deletions .changes/unreleased/Fixed-20240610-123340.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: Fixed
body: Fixed bug where cache setting was not actually being checked
time: 2024-06-10T12:33:40.797971-05:00
custom:
Author: Shackelford-Arden
11 changes: 7 additions & 4 deletions cmd/unset.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"

"github.com/Shackelford-Arden/hctx/cache"
"github.com/urfave/cli/v2"
)
Expand All @@ -16,10 +17,12 @@ func Unset(ctx *cli.Context) error {
}

// Get current stacks tokens, if any and cache them
toCache := cache.GetCacheableValues()
updateErr := AppCache.Update(currentStack.Name, toCache)
if updateErr != nil {
return fmt.Errorf("could not update cache for stack %s: %v", currentStack.Name, updateErr)
if AppConfig.CacheAuth {
toCache := cache.GetCacheableValues()
updateErr := AppCache.Update(currentStack.Name, toCache)
if updateErr != nil {
return fmt.Errorf("could not update cache for stack %s: %v", currentStack.Name, updateErr)
}
}

fmt.Println(currentStack.Unset(AppConfig.Shell))
Expand Down
6 changes: 4 additions & 2 deletions cmd/use.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"

"github.com/Shackelford-Arden/hctx/cache"
"github.com/urfave/cli/v2"
)
Expand All @@ -18,7 +19,8 @@ func Use(ctx *cli.Context) error {

currentStack := AppConfig.GetCurrentStack()
// Get current stacks tokens, if any and cache them
if currentStack != nil {
fmt.Printf("Value of cache_auth: %v", AppConfig.CacheAuth)
if currentStack != nil && AppConfig.CacheAuth {
toCache := cache.GetCacheableValues()
updateErr := AppCache.Update(currentStack.Name, toCache)
if updateErr != nil {
Expand All @@ -29,7 +31,7 @@ func Use(ctx *cli.Context) error {
// rehydrate env w/ new stack cache, if present
newStackCache := AppCache.Get(selectedStack.Name)

fmt.Print(selectedStack.Use(AppConfig.Shell, newStackCache))
fmt.Print(selectedStack.Use(AppConfig.Shell, newStackCache, AppConfig.CacheAuth))

return nil
}
9 changes: 5 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package config

import (
"fmt"
"os"
"strings"

"github.com/Shackelford-Arden/hctx/models"
"github.com/Shackelford-Arden/hctx/types"
"github.com/hashicorp/hcl/v2/hclsimple"
"os"
"strings"
)

const ConfigParentDir = ".config"
Expand Down Expand Up @@ -109,7 +110,7 @@ type Stack struct {
}

// Use provides commands to set appropriate environment variables
func (s *Stack) Use(shell string, cache *models.StackCache) string {
func (s *Stack) Use(shell string, cache *models.StackCache, useCache bool) string {
// Include Stack Name as an environment variable
// Allow the Alias name to show in the environment variable
stackName := s.Name
Expand All @@ -120,7 +121,7 @@ func (s *Stack) Use(shell string, cache *models.StackCache) string {
var nomadToken string
var consulToken string

if cache != nil {
if cache != nil && useCache {
nomadToken = cache.NomadToken
consulToken = cache.ConsulToken
}
Expand Down
9 changes: 5 additions & 4 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package config

import (
"fmt"
"testing"

"github.com/Shackelford-Arden/hctx/models"
"github.com/Shackelford-Arden/hctx/types"
"testing"
)

// region Bash/ZSH
Expand All @@ -17,7 +18,7 @@ func TestNewConfigUseFullNomad(t *testing.T) {
}

stackName := "just_nomad"
useOut := cfg.GetStack(stackName).Use("bash", nil)
useOut := cfg.GetStack(stackName).Use("bash", nil, false)

expectedOutput := fmt.Sprintf(`
export %s='%s'
Expand All @@ -38,7 +39,7 @@ func TestNewConfigUseFullConsul(t *testing.T) {
t.Fatalf("failed to read config: %s", err)
}
stackName := "just_consul"
useOut := cfg.GetStack(stackName).Use("bash", nil)
useOut := cfg.GetStack(stackName).Use("bash", nil, false)

expectedOutput := fmt.Sprintf(`
export %s='%s'
Expand All @@ -60,7 +61,7 @@ func TestNewConfigUseFullVault(t *testing.T) {
}

stackName := "just_vault"
useOut := cfg.GetStack(stackName).Use("bash", nil)
useOut := cfg.GetStack(stackName).Use("bash", nil, false)

expectedOutput := fmt.Sprintf(`
export %s='%s'
Expand Down
Loading