@@ -22,6 +22,8 @@ func init() {
22
22
// NOTE: This list is and should remain alphabetically ordered
23
23
schema .AddType ("ClusterVulnerability" ,
24
24
append (commonVulnerabilitySubResolvers ,
25
+ "clusterCount(query: String): Int!" ,
26
+ "clusters(query: String, pagination: Pagination): [Cluster!]!" ,
25
27
"vulnerabilityType: String!" ,
26
28
"vulnerabilityTypes: [String!]!" ,
27
29
)),
@@ -45,6 +47,8 @@ func init() {
45
47
type ClusterVulnerabilityResolver interface {
46
48
CommonVulnerabilityResolver
47
49
50
+ ClusterCount (ctx context.Context , args RawQuery ) (int32 , error )
51
+ Clusters (ctx context.Context , args PaginatedQuery ) ([]* clusterResolver , error )
48
52
VulnerabilityType () string
49
53
VulnerabilityTypes () []string
50
54
}
@@ -311,9 +315,15 @@ func withOpenShiftTypeFiltering(q string) string {
311
315
}
312
316
313
317
func (resolver * clusterCVEResolver ) withClusterVulnerabilityScope (ctx context.Context ) context.Context {
318
+ if features .PostgresDatastore .Enabled () {
319
+ return scoped .Context (ctx , scoped.Scope {
320
+ ID : resolver .data .GetId (),
321
+ Level : v1 .SearchCategory_CLUSTER_VULNERABILITIES ,
322
+ })
323
+ }
314
324
return scoped .Context (ctx , scoped.Scope {
315
325
ID : resolver .data .GetId (),
316
- Level : v1 .SearchCategory_CLUSTER_VULNERABILITIES ,
326
+ Level : v1 .SearchCategory_VULNERABILITIES ,
317
327
})
318
328
}
319
329
@@ -333,6 +343,26 @@ func (resolver *clusterCVEResolver) getClusterCVEQuery() *v1.Query {
333
343
Sub Resolver Functions
334
344
*/
335
345
346
+ // Clusters returns resolvers for clusters affected by cluster vulnerability.
347
+ func (resolver * clusterCVEResolver ) Clusters (ctx context.Context , args PaginatedQuery ) ([]* clusterResolver , error ) {
348
+ defer metrics .SetGraphQLOperationDurationTime (time .Now (), pkgMetrics .ClusterCVEs , "Clusters" )
349
+
350
+ if err := readClusters (ctx ); err != nil {
351
+ return nil , err
352
+ }
353
+ return resolver .root .Clusters (resolver .withClusterVulnerabilityScope (ctx ), args )
354
+ }
355
+
356
+ // ClusterCount returns a number of clusters affected by cluster vulnerability.
357
+ func (resolver * clusterCVEResolver ) ClusterCount (ctx context.Context , args RawQuery ) (int32 , error ) {
358
+ defer metrics .SetGraphQLOperationDurationTime (time .Now (), pkgMetrics .ClusterCVEs , "ClusterCount" )
359
+
360
+ if err := readClusters (ctx ); err != nil {
361
+ return 0 , err
362
+ }
363
+ return resolver .root .ClusterCount (resolver .withClusterVulnerabilityScope (ctx ), args )
364
+ }
365
+
336
366
func (resolver * clusterCVEResolver ) VulnerabilityType () string {
337
367
return resolver .data .GetType ().String ()
338
368
}
0 commit comments