From 302d6d133b0a4b137d905d71316d147733ee4032 Mon Sep 17 00:00:00 2001 From: artaasadi Date: Tue, 17 Dec 2024 15:02:13 +0100 Subject: [PATCH] fix: fix get audit job --- services/compliance/http_routes.go | 16 ++++++++-------- services/describe/api/describe.go | 1 + services/describe/api/jobs.go | 21 --------------------- services/describe/client/scheduler.go | 6 +++--- 4 files changed, 12 insertions(+), 32 deletions(-) diff --git a/services/compliance/http_routes.go b/services/compliance/http_routes.go index efab5f246..a674a171a 100644 --- a/services/compliance/http_routes.go +++ b/services/compliance/http_routes.go @@ -7690,11 +7690,11 @@ func (h HttpHandler) GetQuickScanSummary(c echo.Context) error { h.logger.Error("failed to get audit job", zap.Error(err)) return echo.NewHTTPError(http.StatusInternalServerError, "failed to get audit job") } - if auditJob.Status == schedulerapi.AuditJobStatusFailed { + if auditJob.Status == schedulerapi.ComplianceJobFailed { return echo.NewHTTPError(http.StatusBadRequest, "job has been failed") - } else if auditJob.Status == schedulerapi.AuditJobStatusTimeOut { - return echo.NewHTTPError(http.StatusBadRequest, "job has been failed") - } else if auditJob.Status == schedulerapi.AuditJobStatusCreated || auditJob.Status == schedulerapi.AuditJobStatusQueued || auditJob.Status == schedulerapi.AuditJobStatusInProgress { + } else if auditJob.Status == schedulerapi.ComplianceJobTimeout { + return echo.NewHTTPError(http.StatusBadRequest, "job has been timed out") + } else if auditJob.Status == schedulerapi.ComplianceJobRunnersInProgress || auditJob.Status == schedulerapi.ComplianceJobCreated || auditJob.Status == schedulerapi.ComplianceJobSummarizerInProgress { return echo.NewHTTPError(http.StatusBadRequest, "job is in progress") } } @@ -7888,11 +7888,11 @@ func (h HttpHandler) GetComplianceJobReport(c echo.Context) error { h.logger.Error("failed to get audit job", zap.Error(err)) return echo.NewHTTPError(http.StatusInternalServerError, "failed to get audit job") } - if auditJob.Status == schedulerapi.AuditJobStatusFailed { - return echo.NewHTTPError(http.StatusBadRequest, "job has been failed") - } else if auditJob.Status == schedulerapi.AuditJobStatusTimeOut { + if auditJob.Status == schedulerapi.ComplianceJobFailed { return echo.NewHTTPError(http.StatusBadRequest, "job has been failed") - } else if auditJob.Status == schedulerapi.AuditJobStatusCreated || auditJob.Status == schedulerapi.AuditJobStatusQueued || auditJob.Status == schedulerapi.AuditJobStatusInProgress { + } else if auditJob.Status == schedulerapi.ComplianceJobTimeout { + return echo.NewHTTPError(http.StatusBadRequest, "job has been timed out") + } else if auditJob.Status == schedulerapi.ComplianceJobRunnersInProgress || auditJob.Status == schedulerapi.ComplianceJobCreated || auditJob.Status == schedulerapi.ComplianceJobSummarizerInProgress { return echo.NewHTTPError(http.StatusBadRequest, "job is in progress") } } diff --git a/services/describe/api/describe.go b/services/describe/api/describe.go index 91795ce15..dd8802ac6 100644 --- a/services/describe/api/describe.go +++ b/services/describe/api/describe.go @@ -30,6 +30,7 @@ const ( ComplianceJobSummarizerInProgress ComplianceJobStatus = "SUMMARIZER_IN_PROGRESS" ComplianceJobFailed ComplianceJobStatus = "FAILED" ComplianceJobSucceeded ComplianceJobStatus = "SUCCEEDED" + ComplianceJobTimeout ComplianceJobStatus = "TIMEOUT" ) type ComplianceJob struct { diff --git a/services/describe/api/jobs.go b/services/describe/api/jobs.go index e1e0fa3b1..314871094 100644 --- a/services/describe/api/jobs.go +++ b/services/describe/api/jobs.go @@ -6,18 +6,6 @@ import ( queryrunner "github.com/opengovern/opencomply/jobs/query-runner-job" ) -type ComplianceQuickRunStatus string - -const ( - AuditJobStatusCreated ComplianceQuickRunStatus = "CREATED" - AuditJobStatusQueued ComplianceQuickRunStatus = "QUEUED" - AuditJobStatusInProgress ComplianceQuickRunStatus = "IN_PROGRESS" - AuditJobStatusFailed ComplianceQuickRunStatus = "FAILED" - AuditJobStatusSucceeded ComplianceQuickRunStatus = "SUCCEEDED" - AuditJobStatusTimeOut ComplianceQuickRunStatus = "TIMEOUT" - AuditJobStatusCanceled ComplianceQuickRunStatus = "CANCELED" -) - type QuickScanSequenceStatus string const ( @@ -416,15 +404,6 @@ type GetIntegrationDiscoveryProgressResponse struct { TriggerIdProgressBreakdown *DiscoveryProgressStatusBreakdown `json:"trigger_id_progress_breakdown"` } -type ComplianceQuickRun struct { - ID string `json:"id"` - FrameworkID string `json:"framework_id"` - IntegrationIDs []string `json:"integration_ids"` - Status ComplianceQuickRunStatus `json:"status"` - FailureMessage string `json:"failure_message"` - CreatedBy string `json:"created_by"` -} - type QuickScanSequence struct { ID string `json:"id"` FrameworkID string `json:"framework_id"` diff --git a/services/describe/client/scheduler.go b/services/describe/client/scheduler.go index 141808f4c..1f676e379 100644 --- a/services/describe/client/scheduler.go +++ b/services/describe/client/scheduler.go @@ -33,7 +33,7 @@ type SchedulerServiceClient interface { ListComplianceJobsHistory(ctx *httpclient.Context, interval, triggerType, createdBy string, cursor, perPage int) (*api.ListComplianceJobsHistoryResponse, error) GetSummaryJobs(ctx *httpclient.Context, jobIDs []string) ([]string, error) GetIntegrationLastDiscoveryJob(ctx *httpclient.Context, request api.GetIntegrationLastDiscoveryJobRequest) (*model.DescribeIntegrationJob, error) - GetComplianceQuickRun(ctx *httpclient.Context, jobID string) (*api.ComplianceQuickRun, error) + GetComplianceQuickRun(ctx *httpclient.Context, jobID string) (*api.ComplianceJob, error) GetComplianceQuickSequence(ctx *httpclient.Context, jobID string) (*api.QuickScanSequence, error) GetComplianceJobStatus(ctx *httpclient.Context, jobId string) (*api.GetComplianceJobStatusResponse, error) } @@ -230,10 +230,10 @@ func (s *schedulerClient) GetIntegrationLastDiscoveryJob(ctx *httpclient.Context return &job, nil } -func (s *schedulerClient) GetComplianceQuickRun(ctx *httpclient.Context, jobID string) (*api.ComplianceQuickRun, error) { +func (s *schedulerClient) GetComplianceQuickRun(ctx *httpclient.Context, jobID string) (*api.ComplianceJob, error) { url := fmt.Sprintf("%s/api/v3/compliance/quick/%s", s.baseURL, jobID) - var job api.ComplianceQuickRun + var job api.ComplianceJob if statusCode, err := httpclient.DoRequest(ctx.Ctx, http.MethodGet, url, ctx.ToHeaders(), nil, &job); err != nil { if 400 <= statusCode && statusCode < 500 { return nil, echo.NewHTTPError(statusCode, err.Error())