core/zero: add support for managed mode from config file

This commit is contained in:
Caleb Doxsey 2023-11-16 12:41:37 -07:00
parent eb729a53f8
commit 78f2793d38
4 changed files with 68 additions and 9 deletions

View file

@ -1,6 +1,10 @@
package cmd
import "os"
import (
"os"
"github.com/spf13/viper"
)
const (
// PomeriumZeroTokenEnv is the environment variable name for the API token.
@ -8,6 +12,20 @@ const (
PomeriumZeroTokenEnv = "POMERIUM_ZERO_TOKEN"
)
func getToken() string {
return os.Getenv(PomeriumZeroTokenEnv)
func getToken(configFile string) string {
if token, ok := os.LookupEnv(PomeriumZeroTokenEnv); ok {
return token
}
if configFile != "" {
// load the token from the config file
v := viper.New()
v.SetConfigFile(configFile)
if v.ReadInConfig() == nil {
return v.GetString("pomerium_zero_token")
}
}
// we will fallback to normal pomerium if empty
return ""
}