From c48aa5fe67f7bab5c89ece681217de8dd0c9221e Mon Sep 17 00:00:00 2001 From: Akshay Bhansali Date: Tue, 24 Aug 2021 11:44:06 +0530 Subject: [PATCH 01/27] Log Errors --- cmd/root.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/root.go b/cmd/root.go index c5f67f1..fa3c9fa 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -74,7 +74,6 @@ func init() { // Initiate segment client if segmentClient, err = segment.NewClient(); err != nil { - log.Fatal().Err(err).Msg("Failed to Create Segment Client: " + err.Error()) } } From fe57b16cf6a03e6a1bd2179515f2e7c7cc2d2862 Mon Sep 17 00:00:00 2001 From: Akshay Bhansali Date: Mon, 30 Aug 2021 12:15:00 +0530 Subject: [PATCH 02/27] dummy commit From 8a0ab1cbb55d871b56ca47a1b7a7f0755cffedc0 Mon Sep 17 00:00:00 2001 From: Akshay Bhansali Date: Tue, 31 Aug 2021 12:44:17 +0530 Subject: [PATCH 03/27] trigger-build From a1a7fb6a00773661ad8b080835a2f7b54167833e Mon Sep 17 00:00:00 2001 From: Akshay Bhansali Date: Tue, 31 Aug 2021 21:43:54 +0530 Subject: [PATCH 04/27] fix readme typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1f1a561..b876f4c 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@

-This repo would server as an interface between the different CRDA clients and the platform. It contains tools that will be used by clients inorder to generate required input for platform APIs. One such tool is `gomanifest`. +This repo would serve as an interface between the different CRDA clients and the platform. It contains tools that will be used by clients inorder to generate required input for platform APIs. One such tool is `gomanifest`. ### Tools and Packages: * `CRDA Cli`: CLI Tools to interact with CRDA Platform. [Learn more](docs/cli_README.md) From d824c7848d287870d458783ec875f4108821bb15 Mon Sep 17 00:00:00 2001 From: Akshay Bhansali Date: Tue, 31 Aug 2021 21:46:53 +0530 Subject: [PATCH 05/27] add break line --- cmd/root.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/root.go b/cmd/root.go index fa3c9fa..c5f67f1 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -74,6 +74,7 @@ func init() { // Initiate segment client if segmentClient, err = segment.NewClient(); err != nil { + log.Fatal().Err(err).Msg("Failed to Create Segment Client: " + err.Error()) } } From 63bb50def9b56e01654604923579a7d3c4011bae Mon Sep 17 00:00:00 2001 From: Akshay Bhansali Date: Tue, 5 Oct 2021 14:56:00 +0530 Subject: [PATCH 06/27] Fix issues with logging in cli --- cmd/analyse.go | 1 + pkg/analyses/stackanalyses/controller.go | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cmd/analyse.go b/cmd/analyse.go index 4e8d61b..5cdefc9 100644 --- a/cmd/analyse.go +++ b/cmd/analyse.go @@ -20,6 +20,7 @@ var verboseOut bool var analyseCmd = &cobra.Command{ Use: "analyse", Short: "Get detailed report of vulnerabilities.", + SilenceUsage: true, Long: `Get detailed report of vulnerabilities. Supported ecosystems are Pypi (Python), Maven (Java), Npm (Node) and Golang (Go). If stack has Vulnerabilities, command will exit with status code 2.`, Args: validateFileArg, diff --git a/pkg/analyses/stackanalyses/controller.go b/pkg/analyses/stackanalyses/controller.go index 18a7512..12746fb 100644 --- a/pkg/analyses/stackanalyses/controller.go +++ b/pkg/analyses/stackanalyses/controller.go @@ -153,8 +153,6 @@ func (mc *Controller) getRequest(requestParams driver.RequestType, postResponse // validatePostResponse validates Stack Analyses POST API Response. func (mc *Controller) validatePostResponse(apiResponse *http.Response) (*driver.PostResponseType, error) { log.Debug().Msgf("Executing validatePostResponse.") - var body driver.PostResponseType - err := json.NewDecoder(apiResponse.Body).Decode(&body) // In Case of Authentication Failure, json is not return from API, Need to catch before decoding. if apiResponse.StatusCode == http.StatusForbidden { @@ -163,6 +161,9 @@ func (mc *Controller) validatePostResponse(apiResponse *http.Response) (*driver. return nil, fmt.Errorf("invalid authentication token") } + var body driver.PostResponseType + err := json.NewDecoder(apiResponse.Body).Decode(&body) + if err != nil { return nil, err } @@ -180,6 +181,10 @@ func (mc *Controller) validateGetResponse(apiResponse *http.Response) (*driver.G log.Debug().Msgf("Executing validateGetResponse.") var body driver.GetResponseType err := json.NewDecoder(apiResponse.Body).Decode(&body) + if err != nil { + log.Error().Msgf("analyse failed: Stack Analyses Get Request Failed Due to An Internal Error. Please retry after sometime. If issue persists, Please raise at https://github.com/fabric8-analytics/cli-tools/issues.") + return nil, fmt.Errorf("stack analysis failed due to an internal error") + } if apiResponse.StatusCode != http.StatusOK { log.Debug().Msgf("Status from Server: %d", apiResponse.StatusCode) log.Error().Msgf("Stack Analyses Get Request Failed with status code %d. Please retry after sometime. If issue persists, Please raise at https://github.com/fabric8-analytics/cli-tools/issues.\"", apiResponse.StatusCode) @@ -211,7 +216,7 @@ func GetMatcher(manifestFile string) (driver.StackAnalysisInterface, error) { return matcher, nil } } - return nil, errors.New("ecosystem not supported yet") + return nil, errors.New("analyse failed: \""+manifestFile+"\" does not appear to be a supported dependency manifest file. Supported manifest files include \"pom.xml\", \"package.json\", \"go.mod\", \"requirements.txt\". Please provide the path of a valid manifest file for analysis. ") } func (mc *Controller) buildFileStats(manifestFile string) *driver.ReadManifestResponse { From aedbc6b9fc5aea206af7a1f3dd1d6849c28ce188 Mon Sep 17 00:00:00 2001 From: Akshay Bhansali Date: Tue, 5 Oct 2021 15:13:31 +0530 Subject: [PATCH 07/27] trigger build From 5198a10651e9a33880aed288895f151453d19b1e Mon Sep 17 00:00:00 2001 From: Akshay Bhansali Date: Tue, 5 Oct 2021 15:18:20 +0530 Subject: [PATCH 08/27] check tests --- pkg/analyses/stackanalyses/controller.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pkg/analyses/stackanalyses/controller.go b/pkg/analyses/stackanalyses/controller.go index 12746fb..dc7085d 100644 --- a/pkg/analyses/stackanalyses/controller.go +++ b/pkg/analyses/stackanalyses/controller.go @@ -181,10 +181,7 @@ func (mc *Controller) validateGetResponse(apiResponse *http.Response) (*driver.G log.Debug().Msgf("Executing validateGetResponse.") var body driver.GetResponseType err := json.NewDecoder(apiResponse.Body).Decode(&body) - if err != nil { - log.Error().Msgf("analyse failed: Stack Analyses Get Request Failed Due to An Internal Error. Please retry after sometime. If issue persists, Please raise at https://github.com/fabric8-analytics/cli-tools/issues.") - return nil, fmt.Errorf("stack analysis failed due to an internal error") - } + if apiResponse.StatusCode != http.StatusOK { log.Debug().Msgf("Status from Server: %d", apiResponse.StatusCode) log.Error().Msgf("Stack Analyses Get Request Failed with status code %d. Please retry after sometime. If issue persists, Please raise at https://github.com/fabric8-analytics/cli-tools/issues.\"", apiResponse.StatusCode) From ee089933224148002f4bd4366f779169b826ec07 Mon Sep 17 00:00:00 2001 From: Akshay Bhansali Date: Tue, 5 Oct 2021 15:24:20 +0530 Subject: [PATCH 09/27] trigger build From c123aa32da554a8e690b4100ae0dcd011163a72d Mon Sep 17 00:00:00 2001 From: Akshay Bhansali Date: Tue, 5 Oct 2021 15:30:32 +0530 Subject: [PATCH 10/27] handle error for invalid response --- pkg/analyses/stackanalyses/controller.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/analyses/stackanalyses/controller.go b/pkg/analyses/stackanalyses/controller.go index dc7085d..12746fb 100644 --- a/pkg/analyses/stackanalyses/controller.go +++ b/pkg/analyses/stackanalyses/controller.go @@ -181,7 +181,10 @@ func (mc *Controller) validateGetResponse(apiResponse *http.Response) (*driver.G log.Debug().Msgf("Executing validateGetResponse.") var body driver.GetResponseType err := json.NewDecoder(apiResponse.Body).Decode(&body) - + if err != nil { + log.Error().Msgf("analyse failed: Stack Analyses Get Request Failed Due to An Internal Error. Please retry after sometime. If issue persists, Please raise at https://github.com/fabric8-analytics/cli-tools/issues.") + return nil, fmt.Errorf("stack analysis failed due to an internal error") + } if apiResponse.StatusCode != http.StatusOK { log.Debug().Msgf("Status from Server: %d", apiResponse.StatusCode) log.Error().Msgf("Stack Analyses Get Request Failed with status code %d. Please retry after sometime. If issue persists, Please raise at https://github.com/fabric8-analytics/cli-tools/issues.\"", apiResponse.StatusCode) From 15a68a13f77826d6846fe18745ec9f21c4231a9a Mon Sep 17 00:00:00 2001 From: Akshay Bhansali Date: Tue, 5 Oct 2021 16:31:37 +0530 Subject: [PATCH 11/27] trigger build From bbb8339bc287bd2df49efa4df76c3c81b23c3537 Mon Sep 17 00:00:00 2001 From: Akshay Bhansali Date: Thu, 7 Oct 2021 13:07:03 +0530 Subject: [PATCH 12/27] change to self hosted apicast URL --- pkg/utils/constants.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/utils/constants.go b/pkg/utils/constants.go index 0ccbcc3..8892809 100644 --- a/pkg/utils/constants.go +++ b/pkg/utils/constants.go @@ -2,8 +2,8 @@ package utils // Flag Defaults const ( - CRDAHost string = "https://f8a-analytics-2445582058137.production.gw.apicast.io" - CRDAAuthToken string = "9e7da76708fe374d8c10fa752e72989f" + CRDAHost string = "https://gw.api.openshift.io" + CRDAAuthToken string = "207c527cfc2a6b8dcf4fa43ad7a976da" Debug bool = false ActualHost string = "https://recommender.api.openshift.io" ) From 66a848d53d0bf84d09d4ecb7051914339423164e Mon Sep 17 00:00:00 2001 From: Akshay Bhansali Date: Tue, 24 Aug 2021 11:44:06 +0530 Subject: [PATCH 13/27] Log Errors --- cmd/root.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/root.go b/cmd/root.go index c5f67f1..fa3c9fa 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -74,7 +74,6 @@ func init() { // Initiate segment client if segmentClient, err = segment.NewClient(); err != nil { - log.Fatal().Err(err).Msg("Failed to Create Segment Client: " + err.Error()) } } From 78125e6ed04e073a478d8348c9df0a673fd77b05 Mon Sep 17 00:00:00 2001 From: Akshay Bhansali Date: Mon, 30 Aug 2021 12:15:00 +0530 Subject: [PATCH 14/27] dummy commit From 1e63ad52aea857dc08baa3259fdd428cdd948dfe Mon Sep 17 00:00:00 2001 From: Akshay Bhansali Date: Tue, 31 Aug 2021 12:44:17 +0530 Subject: [PATCH 15/27] trigger-build From 8a3a40fa64166f4b389c5ff05eda6881c2704ea7 Mon Sep 17 00:00:00 2001 From: Akshay Bhansali Date: Tue, 31 Aug 2021 21:43:54 +0530 Subject: [PATCH 16/27] fix readme typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1f1a561..b876f4c 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@

-This repo would server as an interface between the different CRDA clients and the platform. It contains tools that will be used by clients inorder to generate required input for platform APIs. One such tool is `gomanifest`. +This repo would serve as an interface between the different CRDA clients and the platform. It contains tools that will be used by clients inorder to generate required input for platform APIs. One such tool is `gomanifest`. ### Tools and Packages: * `CRDA Cli`: CLI Tools to interact with CRDA Platform. [Learn more](docs/cli_README.md) From 6731fe4d56bc26c8cd69e68f047e7390ac2e445c Mon Sep 17 00:00:00 2001 From: Akshay Bhansali Date: Tue, 31 Aug 2021 21:46:53 +0530 Subject: [PATCH 17/27] add break line --- cmd/root.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/root.go b/cmd/root.go index fa3c9fa..c5f67f1 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -74,6 +74,7 @@ func init() { // Initiate segment client if segmentClient, err = segment.NewClient(); err != nil { + log.Fatal().Err(err).Msg("Failed to Create Segment Client: " + err.Error()) } } From 903805cf55b16e79b54db8936ba9a9a866eab0e5 Mon Sep 17 00:00:00 2001 From: Akshay Bhansali Date: Tue, 5 Oct 2021 14:56:00 +0530 Subject: [PATCH 18/27] Fix issues with logging in cli --- cmd/analyse.go | 1 + pkg/analyses/stackanalyses/controller.go | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cmd/analyse.go b/cmd/analyse.go index 4e8d61b..5cdefc9 100644 --- a/cmd/analyse.go +++ b/cmd/analyse.go @@ -20,6 +20,7 @@ var verboseOut bool var analyseCmd = &cobra.Command{ Use: "analyse", Short: "Get detailed report of vulnerabilities.", + SilenceUsage: true, Long: `Get detailed report of vulnerabilities. Supported ecosystems are Pypi (Python), Maven (Java), Npm (Node) and Golang (Go). If stack has Vulnerabilities, command will exit with status code 2.`, Args: validateFileArg, diff --git a/pkg/analyses/stackanalyses/controller.go b/pkg/analyses/stackanalyses/controller.go index 18a7512..12746fb 100644 --- a/pkg/analyses/stackanalyses/controller.go +++ b/pkg/analyses/stackanalyses/controller.go @@ -153,8 +153,6 @@ func (mc *Controller) getRequest(requestParams driver.RequestType, postResponse // validatePostResponse validates Stack Analyses POST API Response. func (mc *Controller) validatePostResponse(apiResponse *http.Response) (*driver.PostResponseType, error) { log.Debug().Msgf("Executing validatePostResponse.") - var body driver.PostResponseType - err := json.NewDecoder(apiResponse.Body).Decode(&body) // In Case of Authentication Failure, json is not return from API, Need to catch before decoding. if apiResponse.StatusCode == http.StatusForbidden { @@ -163,6 +161,9 @@ func (mc *Controller) validatePostResponse(apiResponse *http.Response) (*driver. return nil, fmt.Errorf("invalid authentication token") } + var body driver.PostResponseType + err := json.NewDecoder(apiResponse.Body).Decode(&body) + if err != nil { return nil, err } @@ -180,6 +181,10 @@ func (mc *Controller) validateGetResponse(apiResponse *http.Response) (*driver.G log.Debug().Msgf("Executing validateGetResponse.") var body driver.GetResponseType err := json.NewDecoder(apiResponse.Body).Decode(&body) + if err != nil { + log.Error().Msgf("analyse failed: Stack Analyses Get Request Failed Due to An Internal Error. Please retry after sometime. If issue persists, Please raise at https://github.com/fabric8-analytics/cli-tools/issues.") + return nil, fmt.Errorf("stack analysis failed due to an internal error") + } if apiResponse.StatusCode != http.StatusOK { log.Debug().Msgf("Status from Server: %d", apiResponse.StatusCode) log.Error().Msgf("Stack Analyses Get Request Failed with status code %d. Please retry after sometime. If issue persists, Please raise at https://github.com/fabric8-analytics/cli-tools/issues.\"", apiResponse.StatusCode) @@ -211,7 +216,7 @@ func GetMatcher(manifestFile string) (driver.StackAnalysisInterface, error) { return matcher, nil } } - return nil, errors.New("ecosystem not supported yet") + return nil, errors.New("analyse failed: \""+manifestFile+"\" does not appear to be a supported dependency manifest file. Supported manifest files include \"pom.xml\", \"package.json\", \"go.mod\", \"requirements.txt\". Please provide the path of a valid manifest file for analysis. ") } func (mc *Controller) buildFileStats(manifestFile string) *driver.ReadManifestResponse { From 8045b1226d15505d532d3d71129ed22fcb6b14d6 Mon Sep 17 00:00:00 2001 From: Akshay Bhansali Date: Tue, 5 Oct 2021 15:13:31 +0530 Subject: [PATCH 19/27] trigger build From f802337fce6a843111362f7f47446a50009f259d Mon Sep 17 00:00:00 2001 From: Akshay Bhansali Date: Tue, 5 Oct 2021 15:18:20 +0530 Subject: [PATCH 20/27] check tests --- pkg/analyses/stackanalyses/controller.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pkg/analyses/stackanalyses/controller.go b/pkg/analyses/stackanalyses/controller.go index 12746fb..dc7085d 100644 --- a/pkg/analyses/stackanalyses/controller.go +++ b/pkg/analyses/stackanalyses/controller.go @@ -181,10 +181,7 @@ func (mc *Controller) validateGetResponse(apiResponse *http.Response) (*driver.G log.Debug().Msgf("Executing validateGetResponse.") var body driver.GetResponseType err := json.NewDecoder(apiResponse.Body).Decode(&body) - if err != nil { - log.Error().Msgf("analyse failed: Stack Analyses Get Request Failed Due to An Internal Error. Please retry after sometime. If issue persists, Please raise at https://github.com/fabric8-analytics/cli-tools/issues.") - return nil, fmt.Errorf("stack analysis failed due to an internal error") - } + if apiResponse.StatusCode != http.StatusOK { log.Debug().Msgf("Status from Server: %d", apiResponse.StatusCode) log.Error().Msgf("Stack Analyses Get Request Failed with status code %d. Please retry after sometime. If issue persists, Please raise at https://github.com/fabric8-analytics/cli-tools/issues.\"", apiResponse.StatusCode) From c888117309fb272eb1b0629cab2eb25d02583aa5 Mon Sep 17 00:00:00 2001 From: Akshay Bhansali Date: Tue, 5 Oct 2021 15:24:20 +0530 Subject: [PATCH 21/27] trigger build From 696db58eb4f981e8678b66925c97f0780d55413c Mon Sep 17 00:00:00 2001 From: Akshay Bhansali Date: Tue, 5 Oct 2021 15:30:32 +0530 Subject: [PATCH 22/27] handle error for invalid response --- pkg/analyses/stackanalyses/controller.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/analyses/stackanalyses/controller.go b/pkg/analyses/stackanalyses/controller.go index dc7085d..12746fb 100644 --- a/pkg/analyses/stackanalyses/controller.go +++ b/pkg/analyses/stackanalyses/controller.go @@ -181,7 +181,10 @@ func (mc *Controller) validateGetResponse(apiResponse *http.Response) (*driver.G log.Debug().Msgf("Executing validateGetResponse.") var body driver.GetResponseType err := json.NewDecoder(apiResponse.Body).Decode(&body) - + if err != nil { + log.Error().Msgf("analyse failed: Stack Analyses Get Request Failed Due to An Internal Error. Please retry after sometime. If issue persists, Please raise at https://github.com/fabric8-analytics/cli-tools/issues.") + return nil, fmt.Errorf("stack analysis failed due to an internal error") + } if apiResponse.StatusCode != http.StatusOK { log.Debug().Msgf("Status from Server: %d", apiResponse.StatusCode) log.Error().Msgf("Stack Analyses Get Request Failed with status code %d. Please retry after sometime. If issue persists, Please raise at https://github.com/fabric8-analytics/cli-tools/issues.\"", apiResponse.StatusCode) From 2340b0e7e5a34cbffad67aadc236a0b59fb93f35 Mon Sep 17 00:00:00 2001 From: Akshay Bhansali Date: Tue, 5 Oct 2021 16:31:37 +0530 Subject: [PATCH 23/27] trigger build From 899921a854c8ac42390fda1b16f331ddf049dac6 Mon Sep 17 00:00:00 2001 From: Akshay Bhansali Date: Thu, 7 Oct 2021 13:07:03 +0530 Subject: [PATCH 24/27] change to self hosted apicast URL --- pkg/utils/constants.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/utils/constants.go b/pkg/utils/constants.go index 0ccbcc3..8892809 100644 --- a/pkg/utils/constants.go +++ b/pkg/utils/constants.go @@ -2,8 +2,8 @@ package utils // Flag Defaults const ( - CRDAHost string = "https://f8a-analytics-2445582058137.production.gw.apicast.io" - CRDAAuthToken string = "9e7da76708fe374d8c10fa752e72989f" + CRDAHost string = "https://gw.api.openshift.io" + CRDAAuthToken string = "207c527cfc2a6b8dcf4fa43ad7a976da" Debug bool = false ActualHost string = "https://recommender.api.openshift.io" ) From b02d5b584b25ace28ab2d19f242f2af4a347b868 Mon Sep 17 00:00:00 2001 From: Akshay Bhansali Date: Thu, 7 Oct 2021 15:58:37 +0530 Subject: [PATCH 25/27] print string response in case of invalid response from server --- pkg/analyses/stackanalyses/controller.go | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/pkg/analyses/stackanalyses/controller.go b/pkg/analyses/stackanalyses/controller.go index 12746fb..fb2669a 100644 --- a/pkg/analyses/stackanalyses/controller.go +++ b/pkg/analyses/stackanalyses/controller.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "io" + "io/ioutil" "mime/multipart" "net/http" "os" @@ -77,8 +78,8 @@ func (mc *Controller) postRequest(requestParams driver.RequestType, filePath str requestData := utils.HTTPRequestType{ Method: http.MethodPost, Endpoint: APIStackAnalyses, - ThreeScaleToken: requestParams.ThreeScaleToken, - Host: requestParams.Host, + ThreeScaleToken: "3e42fa66f65124e6b1266a23431e3d08", + Host: "https://f8a-analytics-preview-2445582058137.production.gw.apicast.io", UserID: requestParams.UserID, Client: requestParams.Client, } @@ -127,8 +128,8 @@ func (mc *Controller) getRequest(requestParams driver.RequestType, postResponse requestData := utils.HTTPRequestType{ Method: http.MethodGet, Endpoint: APIStackAnalyses + "/" + postResponse.ID, - ThreeScaleToken: requestParams.ThreeScaleToken, - Host: requestParams.Host, + ThreeScaleToken: "3e42fa66f65124e6b1266a23431e3d08", + Host: "https://f8a-analytics-preview-2445582058137.production.gw.apicast.io", UserID: requestParams.UserID, Client: requestParams.Client, } @@ -163,8 +164,8 @@ func (mc *Controller) validatePostResponse(apiResponse *http.Response) (*driver. var body driver.PostResponseType err := json.NewDecoder(apiResponse.Body).Decode(&body) - if err != nil { + return nil, err } if apiResponse.StatusCode != http.StatusOK { @@ -180,11 +181,18 @@ func (mc *Controller) validatePostResponse(apiResponse *http.Response) (*driver. func (mc *Controller) validateGetResponse(apiResponse *http.Response) (*driver.GetResponseType, error) { log.Debug().Msgf("Executing validateGetResponse.") var body driver.GetResponseType - err := json.NewDecoder(apiResponse.Body).Decode(&body) + var buf bytes.Buffer + + //use TeeReader to duplicate the contents of the Response Body of type io.ReaderCloser since data is streamed from the response body. + r := io.TeeReader(apiResponse.Body, &buf) + responseBodyContents, _ :=ioutil.ReadAll(r) + err := json.NewDecoder(&buf).Decode(&body) + if err != nil { - log.Error().Msgf("analyse failed: Stack Analyses Get Request Failed Due to An Internal Error. Please retry after sometime. If issue persists, Please raise at https://github.com/fabric8-analytics/cli-tools/issues.") - return nil, fmt.Errorf("stack analysis failed due to an internal error") + log.Error().Msg("analyse failed: Stack Analyses Get Request Failed. Please retry after sometime. If issue persists, Please raise at https://github.com/fabric8-analytics/cli-tools/issues.") + return nil, fmt.Errorf("Message from Server: "+string(responseBodyContents)) } + if apiResponse.StatusCode != http.StatusOK { log.Debug().Msgf("Status from Server: %d", apiResponse.StatusCode) log.Error().Msgf("Stack Analyses Get Request Failed with status code %d. Please retry after sometime. If issue persists, Please raise at https://github.com/fabric8-analytics/cli-tools/issues.\"", apiResponse.StatusCode) From f36e0f61d3c544abc653a8801efec3c67e6425d4 Mon Sep 17 00:00:00 2001 From: Akshay Bhansali Date: Thu, 7 Oct 2021 16:00:10 +0530 Subject: [PATCH 26/27] restore host and token --- pkg/analyses/stackanalyses/controller.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/analyses/stackanalyses/controller.go b/pkg/analyses/stackanalyses/controller.go index fb2669a..54d32c1 100644 --- a/pkg/analyses/stackanalyses/controller.go +++ b/pkg/analyses/stackanalyses/controller.go @@ -78,8 +78,8 @@ func (mc *Controller) postRequest(requestParams driver.RequestType, filePath str requestData := utils.HTTPRequestType{ Method: http.MethodPost, Endpoint: APIStackAnalyses, - ThreeScaleToken: "3e42fa66f65124e6b1266a23431e3d08", - Host: "https://f8a-analytics-preview-2445582058137.production.gw.apicast.io", + ThreeScaleToken: requestParams.ThreeScaleToken, + Host: requestParams.Host, UserID: requestParams.UserID, Client: requestParams.Client, } @@ -128,8 +128,8 @@ func (mc *Controller) getRequest(requestParams driver.RequestType, postResponse requestData := utils.HTTPRequestType{ Method: http.MethodGet, Endpoint: APIStackAnalyses + "/" + postResponse.ID, - ThreeScaleToken: "3e42fa66f65124e6b1266a23431e3d08", - Host: "https://f8a-analytics-preview-2445582058137.production.gw.apicast.io", + ThreeScaleToken: requestParams.ThreeScaleToken, + Host: requestParams.Host, UserID: requestParams.UserID, Client: requestParams.Client, } From d76888b691cc25c241fabb08e5c9f331241fbac6 Mon Sep 17 00:00:00 2001 From: Akshay Bhansali Date: Thu, 7 Oct 2021 16:56:42 +0530 Subject: [PATCH 27/27] trigger build