machinelock-manager/config/main.go

48 lines
1.5 KiB
Go
Raw Normal View History

2024-12-27 22:47:52 +00:00
package config
import (
"strings"
flag "github.com/spf13/pflag"
"github.com/spf13/viper"
)
var (
Port int
DbType string
Db string
CookieSecret string
MachineToken string
OauthEndpoint string
OauthClientID string
OauthClientSecret string
BaseUrl string
)
func init() {
flag.String("machine-token", "", "Token with wich machines will authenticate")
flag.Int("port", 3000, "Port to listen on")
flag.String("db-type", "sqlite", "Database type: either sqlite or psql")
flag.String("db", "db.sqlite", "Connect string for db")
flag.String("cookie-secret", "", "Secret for the cookie store, leave empty for random secret")
flag.String("oauth-client-id", "", "Oauth2 Client ID")
flag.String("oauth-client-secret", "", "Oauth2 Client Secret")
flag.String("oauth-endpoint", "", "Authentik Endpoint URL")
flag.String("base-url", "http://localhost:3000", "Base URL where this will be hosted")
_ = viper.BindPFlags(flag.CommandLine)
flag.Parse()
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
viper.AutomaticEnv()
Port = viper.GetInt("port")
CookieSecret = viper.GetString("cookie-secret")
MachineToken = viper.GetString("machine-token")
OauthClientID = viper.GetString("oauth-client-id")
OauthClientSecret = viper.GetString("oauth-client-secret")
OauthEndpoint = viper.GetString("oauth-endpoint")
BaseUrl = viper.GetString("base-url")
Db = viper.GetString("db")
DbType = viper.GetString("db-type")
}