Skip to content

Commit

Permalink
feat: Add method to get ttl time remaining
Browse files Browse the repository at this point in the history
  • Loading branch information
tbeaugrand committed Jul 26, 2024
1 parent d524ee7 commit 2b7be14
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
9 changes: 9 additions & 0 deletions internal/libvault/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,12 @@ func CreateClientWithAppRole(roleID, secretID string) (*vault.Client, error) {
client.SetToken(resp.Auth.ClientToken)
return client, nil
}

func GetTokenTtlLeft(client *vault.Client) (int, error) {

Check failure on line 72 in internal/libvault/vault.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: func GetTokenTtlLeft should be GetTokenTTLLeft (revive)
secret, err := client.Auth().Token().LookupSelf()
if err != nil {
return 0, errors.Wrap(err, "failed to lookup token")
}

return int(secret.Data["ttl"].(float64)), nil
}
9 changes: 9 additions & 0 deletions vaultv1/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ func CreateClientWithAppRole(roleID, secretID string) (*Client, error) {
}, nil
}

func GetTokenTtlLeft(client *Client) (int, error) {

Check failure on line 37 in vaultv1/v1.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: func GetTokenTtlLeft should be GetTokenTTLLeft (revive)
timeLeft, err := libvault.GetTokenTtlLeft(client.Client)
if err != nil {
return 0, errors.Wrapf(err, "")
}

return timeLeft, nil
}

func (vc *Client) ListSecretPath(path string) ([]string, error) {
s, err := vc.Client.Logical().List(path)
if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions vaultv2/v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ func CreateClientWithAppRole(roleID, secretID string) (*Client, error) {
}, nil
}

func GetTokenTtlLeft(client *Client) (int, error) {

Check failure on line 38 in vaultv2/v2.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: func GetTokenTtlLeft should be GetTokenTTLLeft (revive)
timeLeft, err := libvault.GetTokenTtlLeft(client.Client)
if err != nil {
return 0, errors.Wrapf(err, "")
}

return timeLeft, nil
}

func (vc *Client) ReadSecret(path string, field string) (string, error) {
secret, err := vc.GetSecret(path)
if err != nil {
Expand Down

0 comments on commit 2b7be14

Please sign in to comment.