backend: Move environment based configuration into backend

This commit is contained in:
Michael Eischer
2023-04-15 10:25:45 +02:00
parent 49a6a4f5bf
commit 2f7b4ceae1
5 changed files with 84 additions and 44 deletions

View File

@@ -1,6 +1,7 @@
package azure
import (
"os"
"path"
"strings"
@@ -53,3 +54,20 @@ func ParseConfig(s string) (interface{}, error) {
cfg.Prefix = prefix
return cfg, nil
}
// ApplyEnvironment saves values from the environment to the config.
func ApplyEnvironment(cfgRaw interface{}) error {
cfg := cfgRaw.(*Config)
if cfg.AccountName == "" {
cfg.AccountName = os.Getenv("AZURE_ACCOUNT_NAME")
}
if cfg.AccountKey.String() == "" {
cfg.AccountKey = options.NewSecretString(os.Getenv("AZURE_ACCOUNT_KEY"))
}
if cfg.AccountSAS.String() == "" {
cfg.AccountSAS = options.NewSecretString(os.Getenv("AZURE_ACCOUNT_SAS"))
}
return nil
}