Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Jira init broken due to authtype value #694

Merged
merged 2 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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