Skip to content

Commit 89f4df0

Browse files
authored
feat(gcp): ContainerAnalysis resources (#5115)
#### Summary See #2586 on why only occurences were implemented (not notes/scanconfigs). <!--
1 parent 2a057fa commit 89f4df0

File tree

10 files changed

+242
-5
lines changed

10 files changed

+242
-5
lines changed

plugins/source/gcp/client/services.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
billing "cloud.google.com/go/billing/apiv1"
88
compute "cloud.google.com/go/compute/apiv1"
99
container "cloud.google.com/go/container/apiv1"
10+
containeranalysis "cloud.google.com/go/containeranalysis/apiv1beta1"
1011
domains "cloud.google.com/go/domains/apiv1beta1"
1112
functions "cloud.google.com/go/functions/apiv1"
1213
kms "cloud.google.com/go/kms/apiv1"
@@ -28,11 +29,12 @@ import (
2829
type GcpService string
2930

3031
type Services struct {
31-
ApikeysClient *apikeys.Client
32-
BigqueryService *bigquery.Service
33-
BillingCloudBillingClient *billing.CloudBillingClient
34-
BillingCloudCatalogClient *billing.CloudCatalogClient
35-
FunctionsCloudFunctionsClient *functions.CloudFunctionsClient
32+
ApikeysClient *apikeys.Client
33+
BigqueryService *bigquery.Service
34+
BillingCloudBillingClient *billing.CloudBillingClient
35+
BillingCloudCatalogClient *billing.CloudCatalogClient
36+
FunctionsCloudFunctionsClient *functions.CloudFunctionsClient
37+
ContaineranalysisGrafeasV1Beta1Client *containeranalysis.GrafeasV1Beta1Client
3638

3739
ComputeAddressesClient *compute.AddressesClient
3840
ComputeAutoscalersClient *compute.AutoscalersClient
@@ -102,6 +104,10 @@ func initServices(ctx context.Context, options []option.ClientOption) (*Services
102104
if err != nil {
103105
return nil, err
104106
}
107+
svcs.ContaineranalysisGrafeasV1Beta1Client, err = containeranalysis.NewGrafeasV1Beta1Client(ctx, options...)
108+
if err != nil {
109+
return nil, err
110+
}
105111
svcs.RunServicesClient, err = run.NewServicesClient(ctx, options...)
106112
if err != nil {
107113
return nil, err

plugins/source/gcp/codegen/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func main() {
3535
resources = append(resources, recipes.IamResources()...)
3636
resources = append(resources, recipes.KmsResources()...)
3737
resources = append(resources, recipes.ContainerResources()...)
38+
resources = append(resources, recipes.ContainerAnalysisResources()...)
3839
resources = append(resources, recipes.LoggingResources()...)
3940
resources = append(resources, recipes.RedisResources()...)
4041
resources = append(resources, recipes.MonitoringResources()...)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package recipes
2+
3+
import (
4+
containeranalysis "cloud.google.com/go/containeranalysis/apiv1beta1"
5+
grafeaspb "cloud.google.com/go/containeranalysis/apiv1beta1/grafeas/grafeaspb"
6+
"github.com/cloudquery/plugin-sdk/codegen"
7+
"github.com/cloudquery/plugin-sdk/schema"
8+
)
9+
10+
func ContainerAnalysisResources() []*Resource {
11+
var resources = []*Resource{
12+
{
13+
SubService: "occurrences",
14+
Struct: &grafeaspb.Occurrence{},
15+
SkipFields: []string{"Name"},
16+
ExtraColumns: []codegen.ColumnDefinition{
17+
ProjectIdColumn,
18+
{
19+
Name: "name",
20+
Type: schema.TypeString,
21+
Resolver: `schema.PathResolver("Name")`,
22+
Options: schema.ColumnCreationOptions{PrimaryKey: true},
23+
},
24+
},
25+
Template: "newapi_list",
26+
ListFunction: (&containeranalysis.GrafeasV1Beta1Client{}).ListOccurrences,
27+
RequestStruct: &grafeaspb.ListOccurrencesRequest{},
28+
ResponseStruct: &grafeaspb.ListOccurrencesResponse{},
29+
RequestStructFields: `Parent: "projects/" + c.ProjectId,`,
30+
},
31+
}
32+
33+
for _, resource := range resources {
34+
resource.Service = "containeranalysis"
35+
36+
resource.MockImports = []string{"cloud.google.com/go/containeranalysis/apiv1beta1"}
37+
resource.ProtobufImport = "cloud.google.com/go/containeranalysis/apiv1beta1/grafeas/grafeaspb"
38+
resource.NewFunction = containeranalysis.NewGrafeasV1Beta1Client
39+
40+
resource.MockTemplate = "newapi_list_grpc_mock"
41+
resource.RegisterServer = grafeaspb.RegisterGrafeasV1Beta1Server
42+
resource.UnimplementedServer = &grafeaspb.UnimplementedGrafeasV1Beta1Server{}
43+
}
44+
45+
return resources
46+
}

plugins/source/gcp/docs/tables/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
- [gcp_kms_keyrings](gcp_kms_keyrings.md)
3131
- [gcp_kms_crypto_keys](gcp_kms_crypto_keys.md)
3232
- [gcp_container_clusters](gcp_container_clusters.md)
33+
- [gcp_containeranalysis_occurrences](gcp_containeranalysis_occurrences.md)
3334
- [gcp_logging_metrics](gcp_logging_metrics.md)
3435
- [gcp_logging_sinks](gcp_logging_sinks.md)
3536
- [gcp_redis_instances](gcp_redis_instances.md)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Table: gcp_containeranalysis_occurrences
2+
3+
4+
5+
The primary key for this table is **name**.
6+
7+
8+
9+
## Columns
10+
| Name | Type |
11+
| ------------- | ------------- |
12+
|_cq_source_name|String|
13+
|_cq_sync_time|Timestamp|
14+
|_cq_id|UUID|
15+
|_cq_parent_id|UUID|
16+
|project_id|String|
17+
|name (PK)|String|
18+
|resource|JSON|
19+
|note_name|String|
20+
|kind|String|
21+
|remediation|String|
22+
|create_time|Timestamp|
23+
|update_time|Timestamp|

plugins/source/gcp/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ require (
77
cloud.google.com/go/billing v1.7.0
88
cloud.google.com/go/compute v1.12.1
99
cloud.google.com/go/container v1.8.0
10+
cloud.google.com/go/containeranalysis v0.6.0
1011
cloud.google.com/go/domains v0.7.0
1112
cloud.google.com/go/functions v1.9.0
1213
cloud.google.com/go/iam v0.7.0

plugins/source/gcp/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ cloud.google.com/go/compute/metadata v0.2.1 h1:efOwf5ymceDhK6PKMnnrTHP4pppY5L22m
5353
cloud.google.com/go/compute/metadata v0.2.1/go.mod h1:jgHgmJd2RKBGzXqF5LR2EZMGxBkeanZ9wwa75XHJgOM=
5454
cloud.google.com/go/container v1.8.0 h1:wib6oN0XQT4r2M4RFfEz0AdfslEQc7H5SDLCV8EZ/lU=
5555
cloud.google.com/go/container v1.8.0/go.mod h1:1ZHYR+yKrEeDs/iBoUNgwyjWNo+WaPN8PRhVnWVCcuA=
56+
cloud.google.com/go/containeranalysis v0.6.0 h1:2824iym832ljKdVpCBnpqm5K94YT/uHTVhNF+dRTXPI=
57+
cloud.google.com/go/containeranalysis v0.6.0/go.mod h1:HEJoiEIu+lEXM+k7+qLCci0h33lX3ZqoYFdmPcoO7s4=
5658
cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE=
5759
cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk=
5860
cloud.google.com/go/domains v0.7.0 h1:pu3JIgC1rswIqi5romW0JgNO6CTUydLYX8zyjiAvO1c=

plugins/source/gcp/resources/plugin/autogen_tables.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/source/gcp/resources/services/containeranalysis/occurrences.go

Lines changed: 88 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/source/gcp/resources/services/containeranalysis/occurrences_mock_test.go

Lines changed: 67 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)