|
33 | 33 |
|
34 | 34 | // sonarDashStatic is a static string used in the dashboard URL. |
35 | 35 | sonarDashStatic = "/dashboard?id=" |
| 36 | + |
| 37 | + // basicAuth is the basic authentication string. |
| 38 | + basicAuth = "Basic " |
36 | 39 | ) |
37 | 40 |
|
38 | 41 | type ( |
@@ -743,7 +746,7 @@ func getStatus(task *TaskResponse, report *SonarReport) string { |
743 | 746 | } |
744 | 747 | sonarToken := os.Getenv("PLUGIN_SONAR_TOKEN") |
745 | 748 | projectRequest, err := http.NewRequest("GET", report.ServerURL+"/api/qualitygates/project_status?"+reportRequest.Encode(), nil) |
746 | | - projectRequest.Header.Add("Authorization", "Basic "+sonarToken) |
| 749 | + projectRequest.Header.Add("Authorization", basicAuth+sonarToken) |
747 | 750 | projectResponse, err := netClient.Do(projectRequest) |
748 | 751 | if err != nil { |
749 | 752 | logrus.WithFields(logrus.Fields{ |
@@ -817,7 +820,7 @@ func getStatusID(taskIDOld string, sonarHost string, projectSlug string) (string |
817 | 820 | fmt.Printf("\n") |
818 | 821 |
|
819 | 822 | // projectRequest, err := http.NewRequest("GET", sonarHost+"/api/qualitygates/project_status?"+reportRequest.Encode(), nil) |
820 | | - // projectRequest.Header.Add("Authorization", "Basic "+token) |
| 823 | + // projectRequest.Header.Add("Authorization", basicAuth+token) |
821 | 824 | // projectResponse, err := netClient.Do(projectRequest) |
822 | 825 | // if err != nil { |
823 | 826 | // logrus.WithFields(logrus.Fields{ |
@@ -888,20 +891,20 @@ func GetProjectStatus(sonarHost string, analysisId string) ([]byte, error) { |
888 | 891 | // fmt.Printf("Setting Authorization header:" + token) |
889 | 892 | // Retry with the token encoded in base64 |
890 | 893 | encodedToken := base64.StdEncoding.EncodeToString([]byte(token)) |
891 | | - projectRequest.Header.Set("Authorization", "Basic "+encodedToken) |
| 894 | + projectRequest.Header.Set("Authorization", basicAuth+encodedToken) |
892 | 895 |
|
893 | | - // projectRequest.Header.Add("Authorization", "Basic "+token) |
| 896 | + // projectRequest.Header.Add("Authorization", basicAuth+token) |
894 | 897 | projectResponse, err := netClient.Do(projectRequest) |
895 | 898 |
|
896 | 899 | if err != nil { |
897 | 900 | fmt.Printf("\n") |
898 | | - fmt.Printf("NIL - Error getting project status, trying again with bearer token...") |
| 901 | + fmt.Printf("NIL - Error getting project status, failed!") |
899 | 902 |
|
900 | 903 | return nil, err |
901 | 904 |
|
902 | 905 | } |
903 | 906 | fmt.Printf("Response Code:" + projectResponse.Status) |
904 | | - buf := []byte{} |
| 907 | + // buf := []byte{} |
905 | 908 | // if status code 401 try again with bearer token |
906 | 909 | if projectResponse.StatusCode == 401 { |
907 | 910 | bearer := "Bearer " + token |
@@ -984,7 +987,7 @@ func GetLatestTaskID(sonarHost string, projectSlug string) (string, error) { |
984 | 987 | fmt.Printf("Retrying with encoded token...\n") |
985 | 988 |
|
986 | 989 | encodedToken := base64.StdEncoding.EncodeToString([]byte(sonarToken)) |
987 | | - req.Header.Add("Authorization", "Basic "+encodedToken) |
| 990 | + req.Header.Add("Authorization", basicAuth+encodedToken) |
988 | 991 | fmt.Printf("Token encoded: %s\n", encodedToken) |
989 | 992 | req.SetBasicAuth(encodedToken, "") |
990 | 993 | resp, err = netClient.Do(req) |
@@ -1032,7 +1035,7 @@ func GetLatestTaskID(sonarHost string, projectSlug string) (string, error) { |
1032 | 1035 | func getSonarJobStatus(report *SonarReport) *TaskResponse { |
1033 | 1036 |
|
1034 | 1037 | taskRequest, err := http.NewRequest("GET", report.CeTaskURL, nil) |
1035 | | - taskRequest.Header.Add("Authorization", "Basic "+os.Getenv("PLUGIN_SONAR_TOKEN")) |
| 1038 | + taskRequest.Header.Add("Authorization", basicAuth+os.Getenv("PLUGIN_SONAR_TOKEN")) |
1036 | 1039 | taskResponse, err := netClient.Do(taskRequest) |
1037 | 1040 | if err != nil { |
1038 | 1041 | logrus.WithFields(logrus.Fields{ |
|
0 commit comments