39 lines
825 B
Go
39 lines
825 B
Go
package locker
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
const PRIVATE_PREFIX = "PRIVATE__"
|
|
|
|
type PrivateSettings = map[string]string
|
|
|
|
var PrivateSettingsInstance *PrivateSettings
|
|
|
|
func Settings() *PrivateSettings {
|
|
if PrivateSettingsInstance != nil {
|
|
return PrivateSettingsInstance
|
|
}
|
|
settings := make(PrivateSettings)
|
|
for _, env := range os.Environ() {
|
|
if len(env) > len(PRIVATE_PREFIX) && env[:len(PRIVATE_PREFIX)] == PRIVATE_PREFIX {
|
|
key := env[len(PRIVATE_PREFIX):strings.Index(env, "=")]
|
|
value := os.Getenv(env[:strings.Index(env, "=")])
|
|
settings[key] = value
|
|
}
|
|
}
|
|
return &settings
|
|
}
|
|
|
|
func GetPrivateEnv(key string) string {
|
|
settings := Settings()
|
|
value := (*settings)[key]
|
|
if value == "" {
|
|
fmt.Println("No private variable found for " + key)
|
|
return ""
|
|
}
|
|
return RSABase64Value(value).Decrypt()
|
|
}
|