Skip to content

Commit

Permalink
more file formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Bill Hamilton <[email protected]>
  • Loading branch information
pacificcode committed Nov 7, 2024
1 parent 08834eb commit d7827cf
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions vault/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,17 @@ type accessTokenResponse struct {
ExpiresIn int `json:"expiresIn"`
}

func (v Vault) setCacheAccessToken(value string, expiresIn int) error {

func (v Vault) setCacheAccessToken(value string, expiresIn int) bool {
cache := TokenCache{}
cache.AccessToken = value
cache.ExpiresIn = (int(time.Now().Unix()) + expiresIn) - int(math.Floor(float64(expiresIn)*0.9))

data, _ := json.Marshal(cache)
data, err := json.Marshal(cache)
if err != nil {
return false
}
os.Setenv("SS_AT", string(data))
return nil
return true
}

func (v Vault) getCacheAccessToken() (string, bool) {
Expand Down Expand Up @@ -222,7 +224,10 @@ func (v Vault) getAccessToken() (string, error) {
if err = json.Unmarshal(response, &resp); err != nil {
return "", fmt.Errorf("unmarshalling token response: %w", err)
}
v.setCacheAccessToken(resp.AccessToken, resp.ExpiresIn)
ok := v.setCacheAccessToken(resp.AccessToken, resp.ExpiresIn)
if !ok {
return "", fmt.Errorf("unable to cache access token")
}
return resp.AccessToken, nil
}

Expand Down

0 comments on commit d7827cf

Please sign in to comment.