Add loglevel and disable update to config struct

This commit is contained in:
Kristoffer Dalby 2022-06-03 10:37:45 +02:00
parent aee8aa1c61
commit 24c9530eee

View file

@ -10,6 +10,7 @@ import (
"time" "time"
"github.com/coreos/go-oidc/v3/oidc" "github.com/coreos/go-oidc/v3/oidc"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/spf13/viper" "github.com/spf13/viper"
"inet.af/netaddr" "inet.af/netaddr"
@ -28,6 +29,8 @@ type Config struct {
IPPrefixes []netaddr.IPPrefix IPPrefixes []netaddr.IPPrefix
PrivateKeyPath string PrivateKeyPath string
BaseDomain string BaseDomain string
LogLevel zerolog.Level
DisableUpdateCheck bool
DERP DERPConfig DERP DERPConfig
@ -381,6 +384,12 @@ func GetHeadscaleConfig() Config {
configuredPrefixes := viper.GetStringSlice("ip_prefixes") configuredPrefixes := viper.GetStringSlice("ip_prefixes")
parsedPrefixes := make([]netaddr.IPPrefix, 0, len(configuredPrefixes)+1) parsedPrefixes := make([]netaddr.IPPrefix, 0, len(configuredPrefixes)+1)
logLevelStr := viper.GetString("log_level")
logLevel, err := zerolog.ParseLevel(logLevelStr)
if err != nil {
logLevel = zerolog.DebugLevel
}
legacyPrefixField := viper.GetString("ip_prefix") legacyPrefixField := viper.GetString("ip_prefix")
if len(legacyPrefixField) > 0 { if len(legacyPrefixField) > 0 {
log. log.
@ -432,6 +441,8 @@ func GetHeadscaleConfig() Config {
MetricsAddr: viper.GetString("metrics_listen_addr"), MetricsAddr: viper.GetString("metrics_listen_addr"),
GRPCAddr: viper.GetString("grpc_listen_addr"), GRPCAddr: viper.GetString("grpc_listen_addr"),
GRPCAllowInsecure: viper.GetBool("grpc_allow_insecure"), GRPCAllowInsecure: viper.GetBool("grpc_allow_insecure"),
DisableUpdateCheck: viper.GetBool("disable_check_updates"),
LogLevel: logLevel,
IPPrefixes: prefixes, IPPrefixes: prefixes,
PrivateKeyPath: AbsolutePathFromConfigPath( PrivateKeyPath: AbsolutePathFromConfigPath(