Skip to content

Commit 907be58

Browse files
authored
Osd 22527: osdctl "jiratoken" flag in "cluster context" command is not used (#678)
* Initial working commit of using passed in jiratoken * changed logic to set jiratoken to viper value if it is defined.
1 parent d01fdcd commit 907be58

File tree

5 files changed

+21
-23
lines changed

5 files changed

+21
-23
lines changed

cmd/cluster/context.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ func (o *contextOptions) generateContextData() (*contextData, []error) {
403403
GetJiraIssues := func() {
404404
defer wg.Done()
405405
defer utils.StartDelayTracker(o.verbose, "Jira Issues").End()
406-
data.JiraIssues, err = utils.GetJiraIssuesForCluster(o.clusterID, o.externalClusterID)
406+
data.JiraIssues, err = utils.GetJiraIssuesForCluster(o.clusterID, o.externalClusterID, o.jiratoken)
407407
if err != nil {
408408
errors = append(errors, fmt.Errorf("error while getting the open jira tickets: %v", err))
409409
}
@@ -412,7 +412,7 @@ func (o *contextOptions) generateContextData() (*contextData, []error) {
412412
GetSupportExceptions := func() {
413413
defer wg.Done()
414414
defer utils.StartDelayTracker(o.verbose, "Support Exceptions").End()
415-
data.SupportExceptions, err = utils.GetJiraSupportExceptionsForOrg(o.organizationID)
415+
data.SupportExceptions, err = utils.GetJiraSupportExceptionsForOrg(o.organizationID, o.jiratoken)
416416
if err != nil {
417417
errors = append(errors, fmt.Errorf("error while getting support exceptions: %v", err))
418418
}

cmd/jira/quick-task.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ package jira
22

33
import (
44
"fmt"
5+
"strings"
6+
57
"github.com/andygrunwald/go-jira"
68
"github.com/openshift/osdctl/pkg/utils"
79
"github.com/spf13/cobra"
810
"github.com/spf13/viper"
9-
"strings"
1011
)
1112

1213
const (
@@ -54,7 +55,7 @@ osdctl jira quick-task "Update command to take new flag" --add-to-sprint
5455
}
5556
boardId := viper.GetInt(BoardIdLabel)
5657

57-
jiraClient, err := utils.GetJiraClient()
58+
jiraClient, err := utils.GetJiraClient("")
5859
if err != nil {
5960
return fmt.Errorf("failed to get Jira client: %w", err)
6061
}

cmd/org/context.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ func addServiceLogs(clusterInfo *ClusterInfo) error {
296296

297297
func addJiraIssues(clusterInfo *ClusterInfo, externalId string) error {
298298
var jiraIssuesErr error
299-
clusterInfo.JiraIssues, jiraIssuesErr = utils.GetJiraIssuesForCluster(clusterInfo.ID, externalId)
299+
clusterInfo.JiraIssues, jiraIssuesErr = utils.GetJiraIssuesForCluster(clusterInfo.ID, externalId, "")
300300
if jiraIssuesErr != nil {
301301
return fmt.Errorf("failed to fetch Jira issues for cluster %v: %v", clusterInfo.ID, jiraIssuesErr)
302302
}

cmd/swarm/secondary.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var secondaryCmd = &cobra.Command{
3535
osdctl swarm secondary`,
3636
RunE: func(cmd *cobra.Command, args []string) error {
3737

38-
jiraClient, err := utils.GetJiraClient()
38+
jiraClient, err := utils.GetJiraClient("")
3939
if err != nil {
4040
return fmt.Errorf("failed to get Jira client: %w", err)
4141
}

pkg/utils/jira.go

+14-17
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,26 @@ const (
1616
// GetJiraClient creates a jira client that connects to
1717
// https://issues.redhat.com. To work, the jiraToken needs to be set in the
1818
// config
19-
func GetJiraClient() (*jira.Client, error) {
20-
var jiratoken string
21-
22-
if !viper.IsSet(JiraTokenConfigKey) {
23-
jiratoken = viper.GetString(JiraTokenConfigKey)
24-
}
25-
26-
if os.Getenv("JIRA_API_TOKEN") != "" {
27-
jiratoken = os.Getenv("JIRA_API_TOKEN")
28-
}
29-
19+
func GetJiraClient(jiratoken string) (*jira.Client, error) {
3020
if jiratoken == "" {
31-
return nil, fmt.Errorf("JIRA token is not defined.")
21+
if viper.IsSet(JiraTokenConfigKey) {
22+
jiratoken = viper.GetString(JiraTokenConfigKey)
23+
}
24+
if os.Getenv("JIRA_API_TOKEN") != "" {
25+
jiratoken = os.Getenv("JIRA_API_TOKEN")
26+
}
27+
if jiratoken == "" {
28+
return nil, fmt.Errorf("JIRA token is not defined")
29+
}
3230
}
33-
3431
tp := jira.PATAuthTransport{
3532
Token: jiratoken,
3633
}
3734
return jira.NewClient(tp.Client(), JiraBaseURL)
3835
}
3936

40-
func GetJiraIssuesForCluster(clusterID string, externalClusterID string) ([]jira.Issue, error) {
41-
jiraClient, err := GetJiraClient()
37+
func GetJiraIssuesForCluster(clusterID string, externalClusterID string, jiratoken string) ([]jira.Issue, error) {
38+
jiraClient, err := GetJiraClient(jiratoken)
4239
if err != nil {
4340
return nil, fmt.Errorf("error connecting to jira: %v", err)
4441
}
@@ -59,8 +56,8 @@ func GetJiraIssuesForCluster(clusterID string, externalClusterID string) ([]jira
5956
return issues, nil
6057
}
6158

62-
func GetJiraSupportExceptionsForOrg(organizationID string) ([]jira.Issue, error) {
63-
jiraClient, err := GetJiraClient()
59+
func GetJiraSupportExceptionsForOrg(organizationID string, jiratoken string) ([]jira.Issue, error) {
60+
jiraClient, err := GetJiraClient(jiratoken)
6461
if err != nil {
6562
return nil, fmt.Errorf("error connecting to jira: %v", err)
6663
}

0 commit comments

Comments
 (0)