Skip to content

Commit d827029

Browse files
authored
feat(gcp-resources): Add translate (#6832)
#### Summary <!-- Explain what problem this PR addresses --> <!--
1 parent 2806d10 commit d827029

8 files changed

Lines changed: 99 additions & 0 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146
- [gcp_sql_users](gcp_sql_users.md)
147147
- [gcp_storage_buckets](gcp_storage_buckets.md)
148148
- [gcp_storage_bucket_policies](gcp_storage_bucket_policies.md)
149+
- [gcp_translate_glossaries](gcp_translate_glossaries.md)
149150
- [gcp_videotranscoder_job_templates](gcp_videotranscoder_job_templates.md)
150151
- [gcp_videotranscoder_jobs](gcp_videotranscoder_jobs.md)
151152
- [gcp_vision_products](gcp_vision_products.md)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Table: gcp_translate_glossaries
2+
3+
https://cloud.google.com/translate/docs/reference/rest/v3/projects.locations.glossaries#resource:-glossary
4+
5+
The composite primary key for this table is (**project_id**, **name**).
6+
7+
## Columns
8+
9+
| Name | Type |
10+
| ------------- | ------------- |
11+
|_cq_source_name|String|
12+
|_cq_sync_time|Timestamp|
13+
|_cq_id|UUID|
14+
|_cq_parent_id|UUID|
15+
|project_id (PK)|String|
16+
|name (PK)|String|
17+
|input_config|JSON|
18+
|entry_count|Int|
19+
|submit_time|Timestamp|
20+
|end_time|Timestamp|

plugins/source/gcp/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ require (
3535
cloud.google.com/go/secretmanager v1.9.0
3636
cloud.google.com/go/serviceusage v1.4.0
3737
cloud.google.com/go/storage v1.28.0
38+
cloud.google.com/go/translate v1.4.0
3839
cloud.google.com/go/video v1.9.0
3940
cloud.google.com/go/vision/v2 v2.5.0
4041
cloud.google.com/go/vmmigration v1.3.0

plugins/source/gcp/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RX
114114
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
115115
cloud.google.com/go/storage v1.28.0 h1:DLrIZ6xkeZX6K70fU/boWx5INJumt6f+nwwWSHXzzGY=
116116
cloud.google.com/go/storage v1.28.0/go.mod h1:qlgZML35PXA3zoEnIkiPLY4/TOkUleufRlu6qmcf7sI=
117+
cloud.google.com/go/translate v1.4.0 h1:AOYOH3MspzJ/bH1YXzB+xTE8fMpn3mwhLjugwGXvMPI=
118+
cloud.google.com/go/translate v1.4.0/go.mod h1:06Dn/ppvLD6WvA5Rhdp029IX2Mi3Mn7fpMRLPvXT5Wg=
117119
cloud.google.com/go/video v1.9.0 h1:ttlvO4J5c1VGq6FkHqWPD/aH6PfdxujHt+muTJlW1Zk=
118120
cloud.google.com/go/video v1.9.0/go.mod h1:0RhNKFRF5v92f8dQt0yhaHrEuH95m068JYOvLZYnJSw=
119121
cloud.google.com/go/vision v1.2.0 h1:/CsSTkbmO9HC8iQpxbK8ATms3OQaX3YQUeTMGCxlaK4=

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
"github.com/cloudquery/plugins/source/gcp/resources/services/serviceusage"
3939
"github.com/cloudquery/plugins/source/gcp/resources/services/sql"
4040
"github.com/cloudquery/plugins/source/gcp/resources/services/storage"
41+
"github.com/cloudquery/plugins/source/gcp/resources/services/translate"
4142
"github.com/cloudquery/plugins/source/gcp/resources/services/videotranscoder"
4243
"github.com/cloudquery/plugins/source/gcp/resources/services/vision"
4344
"github.com/cloudquery/plugins/source/gcp/resources/services/vmmigration"
@@ -141,6 +142,7 @@ func PluginAutoGeneratedTables() []*schema.Table {
141142
serviceusage.Services(),
142143
sql.Instances(),
143144
storage.Buckets(),
145+
translate.Glossaries(),
144146
videotranscoder.Jobs(),
145147
videotranscoder.JobTemplates(),
146148
vision.Products(),
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package translate
2+
3+
import (
4+
pb "cloud.google.com/go/translate/apiv3/translatepb"
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 Glossaries() *schema.Table {
11+
return &schema.Table{
12+
Name: "gcp_translate_glossaries",
13+
Description: `https://cloud.google.com/translate/docs/reference/rest/v3/projects.locations.glossaries#resource:-glossary`,
14+
Resolver: fetchGlossaries,
15+
Multiplex: client.ProjectMultiplexEnabledServices("translate.googleapis.com"),
16+
Transform: transformers.TransformWithStruct(&pb.Glossary{}, 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: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package translate
2+
3+
import (
4+
"context"
5+
6+
translate "cloud.google.com/go/translate/apiv3"
7+
pb "cloud.google.com/go/translate/apiv3/translatepb"
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 fetchGlossaries(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- any) error {
14+
c := meta.(*client.Client)
15+
16+
gcpClient, err := translate.NewTranslationClient(ctx, c.ClientOptions...)
17+
if err != nil {
18+
return err
19+
}
20+
21+
it := gcpClient.ListGlossaries(ctx, &pb.ListGlossariesRequest{
22+
Parent: "projects/" + c.ProjectId + "/locations/global",
23+
}, c.CallOptions...)
24+
for {
25+
resp, err := it.Next()
26+
if err == iterator.Done {
27+
break
28+
}
29+
if err != nil {
30+
return err
31+
}
32+
33+
res <- resp
34+
}
35+
return nil
36+
}

website/pages/docs/plugins/sources/gcp/tables.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146
- [gcp_sql_users](https://github.com/cloudquery/cloudquery/blob/main/plugins/source/gcp/docs/tables/gcp_sql_users.md)
147147
- [gcp_storage_buckets](https://github.com/cloudquery/cloudquery/blob/main/plugins/source/gcp/docs/tables/gcp_storage_buckets.md)
148148
- [gcp_storage_bucket_policies](https://github.com/cloudquery/cloudquery/blob/main/plugins/source/gcp/docs/tables/gcp_storage_bucket_policies.md)
149+
- [gcp_translate_glossaries](https://github.com/cloudquery/cloudquery/blob/main/plugins/source/gcp/docs/tables/gcp_translate_glossaries.md)
149150
- [gcp_videotranscoder_job_templates](https://github.com/cloudquery/cloudquery/blob/main/plugins/source/gcp/docs/tables/gcp_videotranscoder_job_templates.md)
150151
- [gcp_videotranscoder_jobs](https://github.com/cloudquery/cloudquery/blob/main/plugins/source/gcp/docs/tables/gcp_videotranscoder_jobs.md)
151152
- [gcp_vision_products](https://github.com/cloudquery/cloudquery/blob/main/plugins/source/gcp/docs/tables/gcp_vision_products.md)

0 commit comments

Comments
 (0)