GetCachedMasterKey returns the master key only if already cached or available via the environment variable, without prompting interactively.
()
| 72 | // GetCachedMasterKey returns the master key only if already cached or available |
| 73 | // via the environment variable, without prompting interactively. |
| 74 | func GetCachedMasterKey() ([]byte, error) { |
| 75 | masterKeyMu.Lock() |
| 76 | defer masterKeyMu.Unlock() |
| 77 | |
| 78 | if len(masterKey) > 0 { |
| 79 | return masterKey, nil |
| 80 | } |
| 81 | |
| 82 | if envKey := os.Getenv(keyEnvVar); envKey != "" { |
| 83 | key, err := deriveKey([]byte(envKey)) |
| 84 | if err != nil { |
| 85 | return nil, err |
| 86 | } |
| 87 | masterKey = key |
| 88 | return masterKey, nil |
| 89 | } |
| 90 | |
| 91 | return nil, nil |
| 92 | } |
| 93 | |
| 94 | // ClearMasterKey removes the cached master key from memory. |
| 95 | func ClearMasterKey() { |