From 17cdfdd79f42ab52a3cff6882ab958dcfa411bc2 Mon Sep 17 00:00:00 2001 From: Mikhail Fesenko Date: Sat, 15 Oct 2022 01:18:20 +0200 Subject: [PATCH 1/2] maraphon.go: Simplified conditions in method Signed-off-by: Mikhail Fesenko --- discovery/marathon/marathon.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/discovery/marathon/marathon.go b/discovery/marathon/marathon.go index cfd3e2c083..ef897234db 100644 --- a/discovery/marathon/marathon.go +++ b/discovery/marathon/marathon.go @@ -106,14 +106,18 @@ func (c *SDConfig) UnmarshalYAML(unmarshal func(interface{}) error) error { if len(c.AuthToken) > 0 && len(c.AuthTokenFile) > 0 { return errors.New("marathon_sd: at most one of auth_token & auth_token_file must be configured") } - if c.HTTPClientConfig.BasicAuth != nil && (len(c.AuthToken) > 0 || len(c.AuthTokenFile) > 0) { - return errors.New("marathon_sd: at most one of basic_auth, auth_token & auth_token_file must be configured") - } - if (len(c.HTTPClientConfig.BearerToken) > 0 || len(c.HTTPClientConfig.BearerTokenFile) > 0) && (len(c.AuthToken) > 0 || len(c.AuthTokenFile) > 0) { - return errors.New("marathon_sd: at most one of bearer_token, bearer_token_file, auth_token & auth_token_file must be configured") - } - if c.HTTPClientConfig.Authorization != nil && (len(c.AuthToken) > 0 || len(c.AuthTokenFile) > 0) { - return errors.New("marathon_sd: at most one of auth_token, auth_token_file & authorization must be configured") + + isAuthTokenProvided := len(c.AuthToken) > 0 || len(c.AuthTokenFile) > 0 + if isAuthTokenProvided { + if c.HTTPClientConfig.BasicAuth != nil { + return errors.New("marathon_sd: at most one of basic_auth, auth_token & auth_token_file must be configured") + } + if len(c.HTTPClientConfig.BearerToken) > 0 || len(c.HTTPClientConfig.BearerTokenFile) > 0 { + return errors.New("marathon_sd: at most one of bearer_token, bearer_token_file, auth_token & auth_token_file must be configured") + } + if c.HTTPClientConfig.Authorization != nil { + return errors.New("marathon_sd: at most one of auth_token, auth_token_file & authorization must be configured") + } } return c.HTTPClientConfig.Validate() } From 02e11cc2a721be3dd6ae1bc4cb3bc37d65b6db96 Mon Sep 17 00:00:00 2001 From: Mikhail Fesenko Date: Thu, 13 Jul 2023 00:52:27 +0200 Subject: [PATCH 2/2] Fix from discussion Signed-off-by: Mikhail Fesenko --- discovery/marathon/marathon.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/discovery/marathon/marathon.go b/discovery/marathon/marathon.go index ef897234db..3baf79aff3 100644 --- a/discovery/marathon/marathon.go +++ b/discovery/marathon/marathon.go @@ -107,15 +107,13 @@ func (c *SDConfig) UnmarshalYAML(unmarshal func(interface{}) error) error { return errors.New("marathon_sd: at most one of auth_token & auth_token_file must be configured") } - isAuthTokenProvided := len(c.AuthToken) > 0 || len(c.AuthTokenFile) > 0 - if isAuthTokenProvided { - if c.HTTPClientConfig.BasicAuth != nil { + if len(c.AuthToken) > 0 || len(c.AuthTokenFile) > 0 { + switch { + case c.HTTPClientConfig.BasicAuth != nil: return errors.New("marathon_sd: at most one of basic_auth, auth_token & auth_token_file must be configured") - } - if len(c.HTTPClientConfig.BearerToken) > 0 || len(c.HTTPClientConfig.BearerTokenFile) > 0 { + case len(c.HTTPClientConfig.BearerToken) > 0 || len(c.HTTPClientConfig.BearerTokenFile) > 0: return errors.New("marathon_sd: at most one of bearer_token, bearer_token_file, auth_token & auth_token_file must be configured") - } - if c.HTTPClientConfig.Authorization != nil { + case c.HTTPClientConfig.Authorization != nil: return errors.New("marathon_sd: at most one of auth_token, auth_token_file & authorization must be configured") } }