Skip to content

Commit

Permalink
🐛 fix hashi vault (#1801)
Browse files Browse the repository at this point in the history
Migrate #1459

Fixes #1476

Signed-off-by: Dominik Richter <[email protected]>
  • Loading branch information
arlimus authored Sep 20, 2023
1 parent a6bad70 commit 6497412
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions providers-sdk/v1/vault/hashivault/hashivault.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import (
"strings"

"github.com/hashicorp/vault/api"
"github.com/rs/zerolog/log"
"go.mondoo.com/cnquery/providers-sdk/v1/vault"
)

var notImplemented = errors.New("not implemented")

func New(serverURL string, token string) *Vault {
log.Debug().Bool("token-sec", len(token) > 0).Msgf("Using HashiCorp Vault at %s", serverURL)
return &Vault{
Token: token,
APIConfig: api.Config{
Expand Down Expand Up @@ -65,6 +67,7 @@ func validKey(key string) error {

// https://learn.hashicorp.com/tutorials/vault/versioned-kv?in=vault/secrets-management#step-2-write-secrets
func (v *Vault) Get(ctx context.Context, id *vault.SecretID) (*vault.Secret, error) {
log.Debug().Str("secret", id.Key).Msg("gather secret from hashicorp-vault")
c, err := v.client()
if err != nil {
return nil, err
Expand All @@ -86,8 +89,9 @@ func (v *Vault) Get(ctx context.Context, id *vault.SecretID) (*vault.Secret, err
}

return &vault.Secret{
Key: id.Key,
Data: secretBytes,
Key: id.Key,
Data: secretBytes,
Encoding: vault.SecretEncoding_encoding_json,
}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion providers-sdk/v1/vault/hashivault/hashivault_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestHashiVault(t *testing.T) {
require.NoError(t, err)

jsonSecret := make(map[string]string)
err = json.Unmarshal([]byte(newCred.Secret), &jsonSecret)
err = json.Unmarshal(newCred.Data, &jsonSecret)
require.NoError(t, err)

assert.Equal(t, jsonSecret, fields)
Expand Down

0 comments on commit 6497412

Please sign in to comment.