Skip to content

Commit

Permalink
fix: rework TTL remaining time method (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
tbeaugrand authored Jul 26, 2024
1 parent b609555 commit c73dab8
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion internal/libvault/vault.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package libvault

import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"strconv"

"github.com/mitchellh/go-homedir"

Expand Down Expand Up @@ -75,5 +78,16 @@ func GetTokenTTLLeft(client *vault.Client) (int, error) {
return 0, errors.Wrap(err, "failed to lookup token")
}

return int(secret.Data["ttl"].(float64)), nil
ttlRaw, ok := secret.Data["ttl"]
if !ok {
return 0, fmt.Errorf("token TTL not found in the response")
}

ttlStr := ttlRaw.(json.Number).String()
ttl, err := strconv.ParseInt(ttlStr, 10, 64)
if err != nil {
return 0, fmt.Errorf("failed to parse token ttl: %v", err)
}

return int(ttl), nil
}

0 comments on commit c73dab8

Please sign in to comment.