writeCache writes the API key cache to credstore.
(helperCmd, apiKey string)
| 55 | |
| 56 | // writeCache writes the API key cache to credstore. |
| 57 | func writeCache(helperCmd, apiKey string) error { |
| 58 | key := helperCacheKey(helperCmd) |
| 59 | cache := apiKeyCache{ |
| 60 | APIKey: apiKey, |
| 61 | LastFetchTime: time.Now(), |
| 62 | } |
| 63 | |
| 64 | data, err := json.Marshal(cache) |
| 65 | if err != nil { |
| 66 | return err |
| 67 | } |
| 68 | |
| 69 | return SetCredential(key, string(data)) |
| 70 | } |
| 71 | |
| 72 | // needsRefresh checks if the cached key needs to be refreshed |
| 73 | func needsRefresh(cache *apiKeyCache, refreshInterval time.Duration) bool { |
no test coverage detected