fix: Jira init broken due to authtype value ()

This commit is contained in:
Ankit 2024-01-06 21:03:42 +01:00 committed by GitHub
parent 54cec0a650
commit e2f453382e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 6 deletions
internal
cmd/root
config
pkg/jira

View File

@ -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"))
}

View File

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

View File

@ -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)
}