diff --git a/secrets/cache.go b/secrets/cache.go index c9ceccc..1a8a770 100644 --- a/secrets/cache.go +++ b/secrets/cache.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "path/filepath" + "sync" "time" ) @@ -26,6 +27,8 @@ type CacheData struct { CacheExpiry time.Time } +var mutex = &sync.Mutex{} + func IsExpired(cacheExpiry time.Time) bool { return cacheExpiry.Before(time.Now()) } @@ -48,12 +51,14 @@ func GetSecretCache(name string, refresh string) string { secret := secretCache[name] if IsExpired(secret.CacheData.CacheExpiry) || refresh == "1" { + mutex.Lock() secretCache[name] = Secret{ CacheData: CacheData{ Data: GetSecret(name), CacheExpiry: GetCacheExpiry(), }, } + mutex.Unlock() } return secretCache[name].CacheData.Data