-
Notifications
You must be signed in to change notification settings - Fork 11
/
postgresql_users.go
34 lines (28 loc) · 990 Bytes
/
postgresql_users.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 PostgreSQLUsers() *schema.Table {
return &schema.Table{
Name: "yc_mdb_postgresql_users",
Description: `https://cloud.yandex.ru/docs/managed-postgresql/api-ref/grpc/user_service#User1`,
Resolver: fetchPostgreSQLUsers,
Transform: structNameClusterIdTransformer(&postgresql.User{}),
}
}
func fetchPostgreSQLUsers(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().User().UserIterator(ctx, &postgresql.ListUsersRequest{ClusterId: cluster.Id})
for it.Next() {
res <- it.Value()
}
return it.Error()
}