CHE-6577 Add an ability to enable auth for go agents with env variable

6.19.x
Sergii Leshchenko 2017-10-26 15:02:45 +03:00
parent 0250757c20
commit a33aa27e74
3 changed files with 35 additions and 10 deletions

View File

@ -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,

View File

@ -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,

View File

@ -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,