From a33aa27e7446e882e508dc426e09fefe4eb847f5 Mon Sep 17 00:00:00 2001 From: Sergii Leshchenko Date: Thu, 26 Oct 2017 15:02:45 +0300 Subject: [PATCH] CHE-6577 Add an ability to enable auth for go agents with env variable --- agents/go-agents/bootstrapper/cfg/cfg.go | 13 +++++++++++-- agents/go-agents/exec-agent/main.go | 16 ++++++++++++---- agents/go-agents/terminal-agent/main.go | 16 ++++++++++++---- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/agents/go-agents/bootstrapper/cfg/cfg.go b/agents/go-agents/bootstrapper/cfg/cfg.go index b8eef6e69f..3216942f42 100644 --- a/agents/go-agents/bootstrapper/cfg/cfg.go +++ b/agents/go-agents/bootstrapper/cfg/cfg.go @@ -17,6 +17,7 @@ import ( "io/ioutil" "log" "os" + "strconv" "strings" "github.com/eclipse/che/agents/go-agents/bootstrapper/booter" @@ -78,11 +79,19 @@ func init() { "", "WebSocket endpoint where to push logs", ) + // auth configuration + defaultAuthEnabled := false + authEnabledEnv := os.Getenv("CHE_AUTH_ENABLED") + b, e := strconv.ParseBool(authEnabledEnv) + if e == nil { + defaultAuthEnabled = b + } flag.BoolVar( &AuthEnabled, "enable-auth", - false, - "Whether authenication on workspace master is needed", + defaultAuthEnabled, + "whether authenticate requests on workspace master before allowing them to proceed."+ + "By default the value from 'CHE_AUTH_ENABLED' environment variable is used or `false` if it is missing", ) flag.StringVar( &runtimeIDRaw, diff --git a/agents/go-agents/exec-agent/main.go b/agents/go-agents/exec-agent/main.go index f413f28a7e..8daeec815a 100644 --- a/agents/go-agents/exec-agent/main.go +++ b/agents/go-agents/exec-agent/main.go @@ -25,6 +25,7 @@ import ( "github.com/eclipse/che/agents/go-agents/core/process" "github.com/eclipse/che/agents/go-agents/core/rest" "github.com/eclipse/che/agents/go-agents/exec-agent/exec" + "strconv" ) var ( @@ -32,7 +33,7 @@ var ( ) func init() { - config.registerFlags() + config.init() } func main() { @@ -145,7 +146,7 @@ type execAgentConfig struct { processCleanupPeriodInMinutes int } -func (cfg *execAgentConfig) registerFlags() { +func (cfg *execAgentConfig) init() { // server configuration flag.StringVar( &cfg.serverAddress, @@ -175,11 +176,18 @@ func (cfg *execAgentConfig) registerFlags() { ) // auth configuration + defaultAuthEnabled := false + authEnabledEnv := os.Getenv("CHE_AUTH_ENABLED") + b, e := strconv.ParseBool(authEnabledEnv) + if e == nil { + defaultAuthEnabled = b + } flag.BoolVar( &cfg.authEnabled, "enable-auth", - false, - "whether authenicate requests on workspace master before allowing them to proceed", + defaultAuthEnabled, + "whether authenticate requests on workspace master before allowing them to proceed."+ + "By default the value from 'CHE_AUTH_ENABLED' environment variable is used or `false` if it is missing", ) flag.UintVar( &cfg.tokensExpirationTimeoutInMinutes, diff --git a/agents/go-agents/terminal-agent/main.go b/agents/go-agents/terminal-agent/main.go index b9fe3253f2..d383699d5e 100644 --- a/agents/go-agents/terminal-agent/main.go +++ b/agents/go-agents/terminal-agent/main.go @@ -32,6 +32,7 @@ import ( "github.com/eclipse/che/agents/go-agents/core/auth" "github.com/eclipse/che/agents/go-agents/core/rest" "github.com/eclipse/che/agents/go-agents/terminal-agent/term" + "strconv" ) var ( @@ -39,7 +40,7 @@ var ( ) func init() { - config.registerFlags() + config.init() } func main() { @@ -104,7 +105,7 @@ type terminalAgentConfig struct { tokensExpirationTimeoutInMinutes uint } -func (cfg *terminalAgentConfig) registerFlags() { +func (cfg *terminalAgentConfig) init() { // server configuration flag.StringVar( &cfg.serverAddress, @@ -148,11 +149,18 @@ func (cfg *terminalAgentConfig) registerFlags() { ) // auth configuration + defaultAuthEnabled := false + authEnabledEnv := os.Getenv("CHE_AUTH_ENABLED") + b, e := strconv.ParseBool(authEnabledEnv) + if e == nil { + defaultAuthEnabled = b + } flag.BoolVar( &cfg.authEnabled, "enable-auth", - false, - "whether authenicate requests on workspace master before allowing them to proceed", + defaultAuthEnabled, + "whether authenticate requests on workspace master before allowing them to proceed."+ + "By default the value from 'CHE_AUTH_ENABLED' environment variable is used or `false` if it is missing", ) flag.UintVar( &cfg.tokensExpirationTimeoutInMinutes,