-
Notifications
You must be signed in to change notification settings - Fork 11
/
postgresql_databases.go
34 lines (28 loc) · 1.01 KB
/
postgresql_databases.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package mdb
import (
"context"
"fmt"
"github.com/cloudquery/plugin-sdk/v4/schema"
"github.com/yandex-cloud/cq-source-yc/client"
"github.com/yandex-cloud/go-genproto/yandex/cloud/mdb/postgresql/v1"
)
func PostgreSQLDatabases() *schema.Table {
return &schema.Table{
Name: "yc_mdb_postgresql_databases",
Description: `https://cloud.yandex.ru/docs/managed-postgresql/api-ref/grpc/database_service#Database1`,
Resolver: fetchPostgreSQLDatabases,
Transform: structNameClusterIdTransformer(&postgresql.Database{}),
}
}
func fetchPostgreSQLDatabases(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- interface{}) error {
c := meta.(*client.Client)
cluster, ok := parent.Item.(*postgresql.Cluster)
if !ok {
return fmt.Errorf("parent is not type of *postgresql.Cluster: %+v", cluster)
}
it := c.SDK.MDB().PostgreSQL().Database().DatabaseIterator(ctx, &postgresql.ListDatabasesRequest{ClusterId: cluster.Id})
for it.Next() {
res <- it.Value()
}
return it.Error()
}