Skip to content

Commit

Permalink
fix: Jira init broken due to authtype value (#694)
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitpokhrel committed Jan 6, 2024
1 parent 54cec0a commit e2f4533
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion internal/cmd/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
Expand Down
4 changes: 2 additions & 2 deletions internal/config/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type issueTypeFieldConf struct {
}
}

// MTLS authtype specific config.
// JiraCLIMTLSConfig is an authtype specific config.
type JiraCLIMTLSConfig struct {
CaCert string
ClientCert string
Expand Down Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions pkg/jira/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit e2f4533

Please sign in to comment.