diff --git a/cmd/agent/run.go b/cmd/agent/run.go index dda92dd3..97ecbcb8 100644 --- a/cmd/agent/run.go +++ b/cmd/agent/run.go @@ -31,6 +31,12 @@ import ( func run(ctx context.Context) error { cfg := config.Get() + if cfg.API.Key == "" { + return errors.New("env variable \"API_KEY\" is required") + } + if cfg.API.URL == "" { + return errors.New("env variable \"API_URL\" is required") + } remoteLogger := logrus.New() remoteLogger.SetLevel(logrus.Level(cfg.Log.Level)) diff --git a/cmd/monitor/run.go b/cmd/monitor/run.go index e5448d50..defa12d3 100644 --- a/cmd/monitor/run.go +++ b/cmd/monitor/run.go @@ -2,6 +2,7 @@ package monitor import ( "context" + "errors" "fmt" "github.com/sirupsen/logrus" @@ -15,6 +16,12 @@ import ( func run(ctx context.Context) error { cfg := config.Get() + if cfg.API.Key == "" { + return errors.New("env variable \"API_KEY\" is required") + } + if cfg.API.URL == "" { + return errors.New("env variable \"API_URL\" is required") + } remoteLogger := logrus.New() remoteLogger.SetLevel(logrus.Level(cfg.Log.Level)) diff --git a/internal/config/config.go b/internal/config/config.go index 2645cc47..fcae4c15 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -172,13 +172,6 @@ func Get() Config { cfg.Log.ExporterSenderTimeout = LogExporterSendTimeout } - if cfg.API.Key == "" { - required("API_KEY") - } - if cfg.API.URL == "" { - required("API_URL") - } - if !strings.HasPrefix(cfg.API.URL, "https://") && !strings.HasPrefix(cfg.API.URL, "http://") { cfg.API.URL = fmt.Sprintf("https://%s", cfg.API.URL) }