Skip to content

Commit

Permalink
chore: refactor deprecated vault calls (#1768)
Browse files Browse the repository at this point in the history
  • Loading branch information
thevilledev authored Sep 15, 2023
1 parent 38facdc commit 2d446f0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 17 deletions.
8 changes: 4 additions & 4 deletions dependency/vault_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ func renewSecret(clients *ClientSet, d renewer) error {
log.Printf("[TRACE] %s: starting renewer", d)

secret, vaultSecret := d.secrets()
renewer, err := clients.Vault().NewRenewer(&api.RenewerInput{
Secret: vaultSecret,
renewer, err := clients.Vault().NewLifetimeWatcher(&api.LifetimeWatcherInput{
Secret: vaultSecret,
RenewBehavior: api.RenewBehaviorErrorOnErrors,
})
if err != nil {
return err
Expand Down Expand Up @@ -303,8 +304,7 @@ func isKVv2(client *api.Client, path string) (string, bool, error) {
client.SetOutputCurlString(false)
defer client.SetOutputCurlString(currentOutputCurlString)

r := client.NewRequest("GET", "/v1/sys/internal/ui/mounts/"+path)
resp, err := client.RawRequest(r)
resp, err := client.Logical().ReadRaw("sys/internal/ui/mounts/" + path)
if resp != nil {
defer resp.Body.Close()
}
Expand Down
4 changes: 0 additions & 4 deletions dependency/vault_pki.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,6 @@ func (d *VaultPKIQuery) fetchPEMs(clients *ClientSet) ([]byte, error) {
return pems.Bytes(), nil
}

func (d *VaultPKIQuery) stopChan() chan struct{} {
return d.stopCh
}

// CanShare returns if this dependency is shareable.
func (d *VaultPKIQuery) CanShare() bool {
return false
Expand Down
10 changes: 4 additions & 6 deletions dependency/vault_read.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (d *VaultReadQuery) Fetch(clients *ClientSet, opts *QueryOptions,
}
}

err := d.fetchSecret(clients, opts)
err := d.fetchSecret(clients)
if err != nil {
return nil, nil, errors.Wrap(err, d.String())
}
Expand All @@ -96,10 +96,8 @@ func (d *VaultReadQuery) Fetch(clients *ClientSet, opts *QueryOptions,
return respWithMetadata(d.secret)
}

func (d *VaultReadQuery) fetchSecret(clients *ClientSet, opts *QueryOptions,
) error {
opts = opts.Merge(&QueryOptions{})
vaultSecret, err := d.readSecret(clients, opts)
func (d *VaultReadQuery) fetchSecret(clients *ClientSet) error {
vaultSecret, err := d.readSecret(clients)
if err == nil {
printVaultWarnings(d, vaultSecret.Warnings)
d.vaultSecret = vaultSecret
Expand Down Expand Up @@ -140,7 +138,7 @@ func (d *VaultReadQuery) Type() Type {
return TypeVault
}

func (d *VaultReadQuery) readSecret(clients *ClientSet, opts *QueryOptions) (*api.Secret, error) {
func (d *VaultReadQuery) readSecret(clients *ClientSet) (*api.Secret, error) {
vaultClient := clients.Vault()

// Check whether this secret refers to a KV v2 entry if we haven't yet.
Expand Down
6 changes: 3 additions & 3 deletions dependency/vault_write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestVaultWriteSecretKV_Fetch(t *testing.T) {
if err != nil {
t.Fatal(err)
}
act, err := rq.readSecret(clients, nil)
act, err := rq.readSecret(clients)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -134,7 +134,7 @@ func TestVaultWriteSecretKV_Fetch(t *testing.T) {
if err != nil {
t.Fatal(err)
}
act, err := rq.readSecret(clients, nil)
act, err := rq.readSecret(clients)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -166,7 +166,7 @@ func TestVaultWriteSecretKV_Fetch(t *testing.T) {
if err != nil {
t.Fatal(err)
}
act, err := rq.readSecret(clients, nil)
act, err := rq.readSecret(clients)
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 2d446f0

Please sign in to comment.