From e2bf51aed0e4f7832d593f7384889c4a707dd1de Mon Sep 17 00:00:00 2001 From: Vahn Gomes Date: Thu, 1 Feb 2024 17:26:47 -0500 Subject: [PATCH] Add SSL and dev mode flags to agent --- agent/flags.go | 12 ++++++++++++ agent/main.go | 16 +++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/agent/flags.go b/agent/flags.go index 06635d3..0ba0f0f 100644 --- a/agent/flags.go +++ b/agent/flags.go @@ -28,6 +28,12 @@ var flags = []cli.Flag{ Usage: "server address", Value: "localhost:5000", }, + &cli.BoolFlag{ + EnvVars: []string{"ECHOES_SSL"}, + Name: "ssl", + Usage: "enable ssl", + Value: false, + }, &cli.StringFlag{ EnvVars: []string{"ECHOES_AGENT_SECRET"}, Name: "secret", @@ -51,4 +57,10 @@ var flags = []cli.Flag{ Usage: "healthcheck endpoint address", Value: ":5000", }, + &cli.BoolFlag{ + EnvVars: []string{"ECHOES_DEV_MODE"}, + Name: "dev-mode", + Usage: "enable dev mode", + Value: false, + }, } diff --git a/agent/main.go b/agent/main.go index a928fe8..e7e7119 100644 --- a/agent/main.go +++ b/agent/main.go @@ -93,7 +93,21 @@ func runAgent(context *cli.Context) error { if strings.HasPrefix(healthcheckAddress, ":") { healthcheckAddress = "localhost" + healthcheckAddress } - if !checkServerHealth("http://" + healthcheckAddress + "/general/healthcheck") { + + // Build the protocol + protocol := "http" + if context.Bool("ssl") { + protocol = "https" + } + + // Build the healthcheck URL + if context.Bool("dev-mode") { + healthcheckAddress = protocol + "://" + healthcheckAddress + "/general/healthcheck" + } else { + healthcheckAddress = protocol + "://" + healthcheckAddress + "/api/general/healthcheck" + } + + if !checkServerHealth(healthcheckAddress) { log.Error("agent", "Server is not healthy") return nil }