Skip to content

Commit 9ecc4d7

Browse files
authored
feat(gcp-resources): Add missing KMS resources (#6769)
#### Summary Adds missing KMS sources. I moved the locations to a top level table for consistency and since it's required for fetching other resources than key rings. This is not a breaking change as we automatically fetch parents if someone configures a relation <!--
1 parent 6cfda91 commit 9ecc4d7

23 files changed

+534
-114
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,12 @@
122122
- [gcp_iam_roles](gcp_iam_roles.md)
123123
- [gcp_iam_service_accounts](gcp_iam_service_accounts.md)
124124
- [gcp_iam_service_account_keys](gcp_iam_service_account_keys.md)
125-
- [gcp_kms_keyrings](gcp_kms_keyrings.md)
126-
- [gcp_kms_crypto_keys](gcp_kms_crypto_keys.md)
125+
- [gcp_kms_locations](gcp_kms_locations.md)
126+
- [gcp_kms_ekm_connections](gcp_kms_ekm_connections.md)
127+
- [gcp_kms_keyrings](gcp_kms_keyrings.md)
128+
- [gcp_kms_crypto_keys](gcp_kms_crypto_keys.md)
129+
- [gcp_kms_crypto_key_versions](gcp_kms_crypto_key_versions.md)
130+
- [gcp_kms_import_jobs](gcp_kms_import_jobs.md)
127131
- [gcp_logging_metrics](gcp_logging_metrics.md)
128132
- [gcp_logging_sinks](gcp_logging_sinks.md)
129133
- [gcp_monitoring_alert_policies](gcp_monitoring_alert_policies.md)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Table: gcp_kms_crypto_key_versions
2+
3+
https://cloud.google.com/kms/docs/reference/rest/v1/projects.locations.keyRings.cryptoKeys.cryptoKeyVersions#CryptoKeyVersion
4+
5+
The composite primary key for this table is (**project_id**, **name**).
6+
7+
## Relations
8+
9+
This table depends on [gcp_kms_crypto_keys](gcp_kms_crypto_keys.md).
10+
11+
## Columns
12+
13+
| Name | Type |
14+
| ------------- | ------------- |
15+
|_cq_source_name|String|
16+
|_cq_sync_time|Timestamp|
17+
|_cq_id|UUID|
18+
|_cq_parent_id|UUID|
19+
|project_id (PK)|String|
20+
|name (PK)|String|
21+
|state|String|
22+
|protection_level|String|
23+
|algorithm|String|
24+
|attestation|JSON|
25+
|create_time|Timestamp|
26+
|generate_time|Timestamp|
27+
|destroy_time|Timestamp|
28+
|destroy_event_time|Timestamp|
29+
|import_job|String|
30+
|import_time|Timestamp|
31+
|import_failure_reason|String|
32+
|external_protection_level_options|JSON|
33+
|reimport_eligible|Bool|

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ The composite primary key for this table is (**project_id**, **name**).
88

99
This table depends on [gcp_kms_keyrings](gcp_kms_keyrings.md).
1010

11+
The following tables depend on gcp_kms_crypto_keys:
12+
- [gcp_kms_crypto_key_versions](gcp_kms_crypto_key_versions.md)
13+
1114
## Columns
1215

1316
| Name | Type |
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Table: gcp_kms_ekm_connections
2+
3+
https://cloud.google.com/kms/docs/reference/rest/v1/projects.locations.ekmConnections#EkmConnection
4+
5+
The composite primary key for this table is (**project_id**, **name**).
6+
7+
## Relations
8+
9+
This table depends on [gcp_kms_locations](gcp_kms_locations.md).
10+
11+
## Columns
12+
13+
| Name | Type |
14+
| ------------- | ------------- |
15+
|_cq_source_name|String|
16+
|_cq_sync_time|Timestamp|
17+
|_cq_id|UUID|
18+
|_cq_parent_id|UUID|
19+
|project_id (PK)|String|
20+
|name (PK)|String|
21+
|create_time|Timestamp|
22+
|service_resolvers|JSON|
23+
|etag|String|
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Table: gcp_kms_import_jobs
2+
3+
https://cloud.google.com/kms/docs/reference/rest/v1/projects.locations.keyRings.importJobs#ImportJob
4+
5+
The composite primary key for this table is (**project_id**, **name**).
6+
7+
## Relations
8+
9+
This table depends on [gcp_kms_keyrings](gcp_kms_keyrings.md).
10+
11+
## Columns
12+
13+
| Name | Type |
14+
| ------------- | ------------- |
15+
|_cq_source_name|String|
16+
|_cq_sync_time|Timestamp|
17+
|_cq_id|UUID|
18+
|_cq_parent_id|UUID|
19+
|project_id (PK)|String|
20+
|name (PK)|String|
21+
|import_method|String|
22+
|protection_level|String|
23+
|create_time|Timestamp|
24+
|generate_time|Timestamp|
25+
|expire_time|Timestamp|
26+
|expire_event_time|Timestamp|
27+
|state|String|
28+
|public_key|JSON|
29+
|attestation|JSON|

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ The composite primary key for this table is (**project_id**, **name**).
66

77
## Relations
88

9+
This table depends on [gcp_kms_locations](gcp_kms_locations.md).
10+
911
The following tables depend on gcp_kms_keyrings:
1012
- [gcp_kms_crypto_keys](gcp_kms_crypto_keys.md)
13+
- [gcp_kms_import_jobs](gcp_kms_import_jobs.md)
1114

1215
## Columns
1316

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Table: gcp_kms_locations
2+
3+
https://cloud.google.com/kms/docs/reference/rest/v1/projects.locations.keyRings#KeyRing
4+
5+
The composite primary key for this table is (**project_id**, **name**).
6+
7+
## Relations
8+
9+
The following tables depend on gcp_kms_locations:
10+
- [gcp_kms_ekm_connections](gcp_kms_ekm_connections.md)
11+
- [gcp_kms_keyrings](gcp_kms_keyrings.md)
12+
13+
## Columns
14+
15+
| Name | Type |
16+
| ------------- | ------------- |
17+
|_cq_source_name|String|
18+
|_cq_sync_time|Timestamp|
19+
|_cq_id|UUID|
20+
|_cq_parent_id|UUID|
21+
|project_id (PK)|String|
22+
|name (PK)|String|
23+
|location_id|String|
24+
|display_name|String|
25+
|labels|JSON|
26+
|metadata|JSON|

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func PluginAutoGeneratedTables() []*schema.Table {
121121
iam.Roles(),
122122
iam.ServiceAccounts(),
123123
iam.DenyPolicies(),
124-
kms.Keyrings(),
124+
kms.Locations(),
125125
logging.Metrics(),
126126
logging.Sinks(),
127127
monitoring.AlertPolicies(),
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package kms
2+
3+
import (
4+
pb "cloud.google.com/go/kms/apiv1/kmspb"
5+
"github.com/cloudquery/plugin-sdk/schema"
6+
"github.com/cloudquery/plugin-sdk/transformers"
7+
"github.com/cloudquery/plugins/source/gcp/client"
8+
)
9+
10+
func CryptoKeyVersions() *schema.Table {
11+
return &schema.Table{
12+
Name: "gcp_kms_crypto_key_versions",
13+
Description: `https://cloud.google.com/kms/docs/reference/rest/v1/projects.locations.keyRings.cryptoKeys.cryptoKeyVersions#CryptoKeyVersion`,
14+
Resolver: fetchCryptoKeyVersions,
15+
Multiplex: client.ProjectMultiplexEnabledServices("cloudkms.googleapis.com"),
16+
Transform: transformers.TransformWithStruct(&pb.CryptoKeyVersion{}, client.Options()...),
17+
Columns: []schema.Column{
18+
{
19+
Name: "project_id",
20+
Type: schema.TypeString,
21+
Resolver: client.ResolveProject,
22+
CreationOptions: schema.ColumnCreationOptions{
23+
PrimaryKey: true,
24+
},
25+
},
26+
{
27+
Name: "name",
28+
Type: schema.TypeString,
29+
Resolver: schema.PathResolver("Name"),
30+
CreationOptions: schema.ColumnCreationOptions{
31+
PrimaryKey: true,
32+
},
33+
},
34+
},
35+
}
36+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package kms
2+
3+
import (
4+
"context"
5+
6+
kms "cloud.google.com/go/kms/apiv1"
7+
"cloud.google.com/go/kms/apiv1/kmspb"
8+
"github.com/cloudquery/plugin-sdk/schema"
9+
"github.com/cloudquery/plugins/source/gcp/client"
10+
"google.golang.org/api/iterator"
11+
)
12+
13+
func fetchCryptoKeyVersions(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- any) error {
14+
c := meta.(*client.Client)
15+
p := parent.Item.(*kmspb.CryptoKey)
16+
kmsClient, err := kms.NewKeyManagementClient(ctx, c.ClientOptions...)
17+
if err != nil {
18+
return err
19+
}
20+
21+
it := kmsClient.ListCryptoKeyVersions(ctx, &kmspb.ListCryptoKeyVersionsRequest{Parent: p.Name})
22+
for {
23+
key, err := it.Next()
24+
if err == iterator.Done {
25+
break
26+
}
27+
if err != nil {
28+
return err
29+
}
30+
res <- key
31+
}
32+
return nil
33+
}

0 commit comments

Comments
 (0)