From d7827cfe8005f99d5b7c6b7864c8e48846ca9f11 Mon Sep 17 00:00:00 2001 From: Bill Hamilton Date: Thu, 7 Nov 2024 08:30:30 -0800 Subject: [PATCH] more file formatting Signed-off-by: Bill Hamilton --- vault/vault.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/vault/vault.go b/vault/vault.go index 76db27f..1a20111 100644 --- a/vault/vault.go +++ b/vault/vault.go @@ -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) { @@ -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 }