From bde11319182880a7409f24dadf84987f9ac40d86 Mon Sep 17 00:00:00 2001 From: Vernell Parker Date: Wed, 16 Jun 2021 17:40:26 -0400 Subject: [PATCH] Added and removed some error handling --- pkg/qualys/api_cloudview.go | 40 +++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/pkg/qualys/api_cloudview.go b/pkg/qualys/api_cloudview.go index 3a3727c..705a0cb 100644 --- a/pkg/qualys/api_cloudview.go +++ b/pkg/qualys/api_cloudview.go @@ -120,7 +120,6 @@ func getAccountType(accountID string) string { // GetCloudAccountEvaluations was refactored with the ability to determine the account type via the getAccountType function. This removes unnecessary calls to the qualys api func (session *Session) GetCloudAccountEvaluations(accountID string) (evaluations []AccountEvaluationContent, cloudAccountType string, err error) { accountType := getAccountType(accountID) - var evals []AccountEvaluationContent if evals, err = session.GetCloudAccountEvaluationsWithCloudAccountType(accountID, accountType); err != nil { @@ -144,29 +143,26 @@ func (session *Session) GetCloudAccountEvaluationsWithCloudAccountType(accountID "%3A%5Bnow-24h%20..%20now-1s%5D%20and%20(policy.name%3ACIS%20Amazon%20Web%20Services%20Foundations%20Benchmark%20or%20policy.name%3AAegis%20AWS%20Benchmark%20or%20policy.name%3ACIS%20Microsoft%20Azure%20Foundations%20Benchmark%20or%20policy.name%3ACIS%20Google%20Cloud%20Platform%20Foundation%20Benchmark)", nil) - if err != nil { - err = session.makeRequest(false, req, func(resp *http.Response) (err error) { - var body []byte - body, err = ioutil.ReadAll(resp.Body) - if err == nil { - err = json.Unmarshal(body, accountEvaluation) - } else { - err = fmt.Errorf("error while reading response body - %s", err.Error()) - } - - return err - }) - } else { - err = fmt.Errorf("error while making request - %s", err.Error()) + if err != nil{ + err = fmt.Errorf("error creating url for request to Qualys - %s", err.Error()) + return nil, err } - if err == nil { - evaluations = append(evaluations, accountEvaluation.Content...) - lastAccPage = accountEvaluation.Last - accPage++ - } else { - break - } + err = session.makeRequest(false, req, func(resp *http.Response) (err error) { + var body []byte + body, err = ioutil.ReadAll(resp.Body) + if err == nil { + err = json.Unmarshal(body, accountEvaluation) + } else { + err = fmt.Errorf("error while reading response body - %s", err.Error()) + } + + return err + }) + + evaluations = append(evaluations, accountEvaluation.Content...) + lastAccPage = accountEvaluation.Last + accPage++ } return evaluations, err