Skip to content

Commit

Permalink
fix: fix get audit job
Browse files Browse the repository at this point in the history
  • Loading branch information
artaasadi committed Dec 17, 2024
1 parent b4f11ea commit 302d6d1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 32 deletions.
16 changes: 8 additions & 8 deletions services/compliance/http_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Expand Down Expand Up @@ -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")
}
}
Expand Down
1 change: 1 addition & 0 deletions services/describe/api/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const (
ComplianceJobSummarizerInProgress ComplianceJobStatus = "SUMMARIZER_IN_PROGRESS"
ComplianceJobFailed ComplianceJobStatus = "FAILED"
ComplianceJobSucceeded ComplianceJobStatus = "SUCCEEDED"
ComplianceJobTimeout ComplianceJobStatus = "TIMEOUT"
)

type ComplianceJob struct {
Expand Down
21 changes: 0 additions & 21 deletions services/describe/api/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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"`
Expand Down
6 changes: 3 additions & 3 deletions services/describe/client/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 302d6d1

Please sign in to comment.