From e2f453382e4d80921b19b4de1fa54ca58e3226a8 Mon Sep 17 00:00:00 2001 From: Ankit Date: Sat, 6 Jan 2024 21:03:42 +0100 Subject: [PATCH] fix: Jira init broken due to authtype value (#694) --- internal/cmd/root/root.go | 2 +- internal/config/generator.go | 4 ++-- pkg/jira/client.go | 9 ++++++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/internal/cmd/root/root.go b/internal/cmd/root/root.go index 3c82787e..ee121b59 100644 --- a/internal/cmd/root/root.go +++ b/internal/cmd/root/root.go @@ -77,7 +77,7 @@ func NewCmdRoot() *cobra.Command { return } - // mtls doesn't need Jira API Token + // mTLS doesn't need Jira API Token. if viper.GetString("auth_type") != string(jira.AuthTypeMTLS) { checkForJiraToken(viper.GetString("server"), viper.GetString("login")) } diff --git a/internal/config/generator.go b/internal/config/generator.go index 87bc24d8..c37607a5 100644 --- a/internal/config/generator.go +++ b/internal/config/generator.go @@ -54,7 +54,7 @@ type issueTypeFieldConf struct { } } -// MTLS authtype specific config. +// JiraCLIMTLSConfig is an authtype specific config. type JiraCLIMTLSConfig struct { CaCert string ClientCert string @@ -232,7 +232,7 @@ func (c *JiraCLIConfigGenerator) configureLocalAuthType() error { } } - if authType == strings.ToLower(jira.AuthTypeMTLS.String()) { + if authType == jira.AuthTypeMTLS.String() { c.value.authType = jira.AuthTypeMTLS } else { c.value.authType = jira.AuthTypeBasic diff --git a/pkg/jira/client.go b/pkg/jira/client.go index eaa23efb..0171e64e 100644 --- a/pkg/jira/client.go +++ b/pkg/jira/client.go @@ -96,7 +96,7 @@ func (e Errors) String() string { // Header is a key, value pair for request headers. type Header map[string]string -// MTLS authtype specific config. +// MTLSConfig is MTLS authtype specific config. type MTLSConfig struct { CaCert string ClientCert string @@ -261,9 +261,12 @@ func (c *Client) request(ctx context.Context, method, endpoint string, body []by req.Header.Set(k, v) } - if c.authType == AuthTypeBearer { + // When need to compare using `String()` here, it is used to handle cases where the + // authentication type might be empty, ensuring it defaults to the appropriate value. + switch c.authType.String() { + case string(AuthTypeBearer): req.Header.Add("Authorization", "Bearer "+c.token) - } else if c.authType == AuthTypeBasic { + case string(AuthTypeBasic): req.SetBasicAuth(c.login, c.token) }