From 646d17bcfe457c6816566b50cfc9df62906f53cc Mon Sep 17 00:00:00 2001 From: thtri Date: Mon, 16 Oct 2023 13:06:30 +0200 Subject: [PATCH] CheckmarxOne: Fix 1st scan failed due to 403 forbiden (#4633) * fix(cxone): 1st scan failed due to 403 forbiden * fix(cxone): 1st scan failed due to 403 forbiden * fix(cxone): 1st scan failed due to 403 forbiden --- pkg/checkmarxone/checkmarxone.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pkg/checkmarxone/checkmarxone.go b/pkg/checkmarxone/checkmarxone.go index e54dfec87..296d64a99 100644 --- a/pkg/checkmarxone/checkmarxone.go +++ b/pkg/checkmarxone/checkmarxone.go @@ -838,6 +838,26 @@ func (sys *SystemInstance) CreateProjectInApplication(projectName, applicationID } err = json.Unmarshal(data, &project) + if err != nil { + return project, errors.Wrapf(err, "failed to unmarshal project data") + } + + // since there is a delay to assign a project to an application, adding a check to ensure project is ready after creation + // (if project is not ready, 403 will be returned) + projectID := project.ProjectID + project, err = sys.GetProjectByID(projectID) + if err != nil { + const max_retry = 12 // 3 minutes + const delay = 15 + retry_counter := 1 + for retry_counter <= max_retry && err != nil { + sys.logger.Debug("Waiting for project assignment to application, retry #", retry_counter) + time.Sleep(delay * time.Second) + retry_counter++ + project, err = sys.GetProjectByID(projectID) + } + } + return project, err }