diff --git a/pkg/cloudql/client/artifact_vulnerabilities.go b/pkg/cloudql/client/artifact_vulnerabilities.go index a723e1e8d..7dbab9547 100644 --- a/pkg/cloudql/client/artifact_vulnerabilities.go +++ b/pkg/cloudql/client/artifact_vulnerabilities.go @@ -58,14 +58,26 @@ type VulnerabilityFix struct { State string `json:"state"` } +type ArtifactVulnerabilitiesTaskResult struct { + PlatformID string `json:"platform_id"` + ResourceID string `json:"resource_id"` + ResourceName string `json:"resource_name"` + Description OciArtifactVulnerabilities `json:"description"` + TaskType string `json:"task_type"` + ResultType string `json:"result_type"` + Metadata map[string]string `json:"metadata"` + DescribedBy string `json:"described_by"` + DescribedAt int64 `json:"described_at"` +} + type OciArtifactVulnerabilitiesHit struct { - ID string `json:"_id"` - Score float64 `json:"_score"` - Index string `json:"_index"` - Type string `json:"_type"` - Version int64 `json:"_version,omitempty"` - Source OciArtifactVulnerabilities `json:"_source"` - Sort []any `json:"sort"` + ID string `json:"_id"` + Score float64 `json:"_score"` + Index string `json:"_index"` + Type string `json:"_type"` + Version int64 `json:"_version,omitempty"` + Source ArtifactVulnerabilitiesTaskResult `json:"_source"` + Sort []any `json:"sort"` } type OciArtifactVulnerabilitiesHits struct { @@ -103,14 +115,14 @@ func (p OciArtifactVulnerabilitiesPaginator) Close(ctx context.Context) error { return p.paginator.Deallocate(ctx) } -func (p OciArtifactVulnerabilitiesPaginator) NextPage(ctx context.Context) ([]OciArtifactVulnerabilities, error) { +func (p OciArtifactVulnerabilitiesPaginator) NextPage(ctx context.Context) ([]ArtifactVulnerabilitiesTaskResult, error) { var response OciArtifactVulnerabilitiesSearchResponse err := p.paginator.SearchWithLog(ctx, &response, true) if err != nil { return nil, err } - var values []OciArtifactVulnerabilities + var values []ArtifactVulnerabilitiesTaskResult for _, hit := range response.Hits.Hits { values = append(values, hit.Source) } @@ -126,8 +138,8 @@ func (p OciArtifactVulnerabilitiesPaginator) NextPage(ctx context.Context) ([]Oc } var artifactVulnerabilitiesMapping = map[string]string{ - "image_url": "imageUrl", - "artifact_digest": "artifactDigest", + "image_url": "Description.imageUrl", + "artifact_digest": "Description.artifactDigest", } func ListArtifactVulnerabilities(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (any, error) { diff --git a/pkg/cloudql/tables/table_platform_artifact_vulnerabilities.go b/pkg/cloudql/tables/table_platform_artifact_vulnerabilities.go index 9678f0fc3..e08a7ba84 100644 --- a/pkg/cloudql/tables/table_platform_artifact_vulnerabilities.go +++ b/pkg/cloudql/tables/table_platform_artifact_vulnerabilities.go @@ -22,17 +22,17 @@ func tablePlatformArtifactVulnerabilities(_ context.Context) *plugin.Table { Columns: []*plugin.Column{ { Name: "image_url", - Transform: transform.FromField("imageUrl"), + Transform: transform.FromField("Description.imageUrl"), Type: proto.ColumnType_STRING, }, { Name: "artifact_digest", - Transform: transform.FromField("artifactDigest"), + Transform: transform.FromField("Description.artifactDigest"), Type: proto.ColumnType_STRING, }, { Name: "vulnerabilities", - Transform: transform.FromField("Vulnerabilities"), + Transform: transform.FromField("Description.Vulnerabilities"), Type: proto.ColumnType_JSON, }, }, diff --git a/services/describe/api/jobs.go b/services/describe/api/jobs.go index d0bd75f4b..cd1696ecb 100644 --- a/services/describe/api/jobs.go +++ b/services/describe/api/jobs.go @@ -179,10 +179,14 @@ type RunBenchmarkResponse struct { Jobs []RunBenchmarkItem `json:"jobs"` } +type ResourceTypeRunDiscoveryRequest struct { + ResourceType string `json:"resource_type"` + Parameters map[string][]string `json:"parameters"` +} + type RunDiscoveryRequest struct { - ResourceTypes []string `json:"resource_types"` - IntegrationInfo []IntegrationInfoFilter `json:"integration_info"` - Parameters map[string][]string `json:"parameters"` + ResourceTypes []ResourceTypeRunDiscoveryRequest `json:"resource_types"` + IntegrationInfo []IntegrationInfoFilter `json:"integration_info"` } type RunDiscoveryJob struct { diff --git a/services/describe/server.go b/services/describe/server.go index 86bdf2fa9..bd6e37552 100644 --- a/services/describe/server.go +++ b/services/describe/server.go @@ -1502,6 +1502,12 @@ func (h HttpServer) RunDiscovery(ctx echo.Context) error { continue } rtToDescribe := request.ResourceTypes + + var resourceTypesNames []string + for _, rt := range rtToDescribe { + resourceTypesNames = append(resourceTypesNames, rt.ResourceType) + } + discoveryType := model2.DiscoveryType_Fast integrationDiscovery := &model2.IntegrationDiscovery{ TriggerID: uint(triggerId), @@ -1510,7 +1516,7 @@ func (h HttpServer) RunDiscovery(ctx echo.Context) error { TriggerType: enums.DescribeTriggerTypeManual, TriggeredBy: userID, DiscoveryType: discoveryType, - ResourceTypes: rtToDescribe, + ResourceTypes: resourceTypesNames, } err = h.DB.CreateIntegrationDiscovery(integrationDiscovery) if err != nil { @@ -1528,9 +1534,11 @@ func (h HttpServer) RunDiscovery(ctx echo.Context) error { h.Scheduler.logger.Error("failed to get resource types by labels", zap.Error(err)) return echo.NewHTTPError(http.StatusInternalServerError, "failed to get resource types by labels") } - var possibleRt []string + var possibleRt []api.ResourceTypeRunDiscoveryRequest for rt, _ := range possibleRtMap { - possibleRt = append(possibleRt, rt) + possibleRt = append(possibleRt, api.ResourceTypeRunDiscoveryRequest{ + ResourceType: rt, + }) } if len(rtToDescribe) == 0 { rtToDescribe = possibleRt @@ -1539,7 +1547,7 @@ func (h HttpServer) RunDiscovery(ctx echo.Context) error { for _, resourceType := range rtToDescribe { isOK := false for _, rt := range possibleRt { - if rt == resourceType { + if rt.ResourceType == resourceType.ResourceType { isOK = true } } @@ -1547,12 +1555,12 @@ func (h HttpServer) RunDiscovery(ctx echo.Context) error { continue } var status, failureReason string - job, err := h.Scheduler.describe(integration, resourceType, false, false, false, &integrationDiscovery.ID, userID, request.Parameters) + job, err := h.Scheduler.describe(integration, resourceType.ResourceType, false, false, false, &integrationDiscovery.ID, userID, resourceType.Parameters) if err != nil { if err.Error() == "job already in progress" { - tmpJob, err := h.Scheduler.db.GetLastDescribeIntegrationJob(integration.IntegrationID, resourceType) + tmpJob, err := h.Scheduler.db.GetLastDescribeIntegrationJob(integration.IntegrationID, resourceType.ResourceType) if err != nil { - h.Scheduler.logger.Error("failed to get last describe job", zap.String("resource_type", resourceType), zap.String("connection_id", integration.IntegrationID), zap.Error(err)) + h.Scheduler.logger.Error("failed to get last describe job", zap.String("resource_type", resourceType.ResourceType), zap.String("connection_id", integration.IntegrationID), zap.Error(err)) } h.Scheduler.logger.Error("failed to describe connection", zap.String("integration_id", integration.IntegrationID), zap.Error(err)) status = "FAILED" @@ -1574,7 +1582,7 @@ func (h HttpServer) RunDiscovery(ctx echo.Context) error { } jobs = append(jobs, api.RunDiscoveryJob{ JobId: jobId, - ResourceType: resourceType, + ResourceType: resourceType.ResourceType, Status: status, FailureReason: failureReason, IntegrationInfo: api.IntegrationInfo{