wallet/pkg/locker/settings.go
Anton Nesterov b19bf34e5f
[init]
2024-08-31 16:54:43 +02:00

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()
}