From ff134f2b8e7ca44ca81f9069e46de805d8472335 Mon Sep 17 00:00:00 2001 From: Juan Font Alonso Date: Fri, 18 Nov 2022 18:02:34 +0100 Subject: [PATCH] Fix remote CLI when there is no config file present --- config.go | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/config.go b/config.go index 0661775..b902792 100644 --- a/config.go +++ b/config.go @@ -185,6 +185,10 @@ func LoadConfig(path string, isFile bool) error { viper.SetDefault("node_update_check_interval", "10s") + if IsCLIConfigured() { + return nil + } + if err := viper.ReadInConfig(); err != nil { log.Warn().Err(err).Msg("Failed to read configuration from disk") @@ -480,6 +484,17 @@ func GetDNSConfig() (*tailcfg.DNSConfig, string) { } func GetHeadscaleConfig() (*Config, error) { + if IsCLIConfigured() { + return &Config{ + CLI: CLIConfig{ + Address: viper.GetString("cli.address"), + APIKey: viper.GetString("cli.api_key"), + Timeout: viper.GetDuration("cli.timeout"), + Insecure: viper.GetBool("cli.insecure"), + }, + }, nil + } + dnsConfig, baseDomain := GetDNSConfig() derpConfig := GetDERPConfig() logConfig := GetLogTailConfig() @@ -580,15 +595,12 @@ func GetHeadscaleConfig() (*Config, error) { LogTail: logConfig, RandomizeClientPort: randomizeClientPort, - CLI: CLIConfig{ - Address: viper.GetString("cli.address"), - APIKey: viper.GetString("cli.api_key"), - Timeout: viper.GetDuration("cli.timeout"), - Insecure: viper.GetBool("cli.insecure"), - }, - ACL: GetACLConfig(), Log: GetLogConfig(), }, nil } + +func IsCLIConfigured() bool { + return viper.GetString("cli.address") != "" && viper.GetString("cli.api_key") != "" +}