Skip to content

Commit b8fadf2

Browse files
pisohakakabachook
authored andcommitted
Add postgresql backups resource
We need to get an information about managed postgresql servers backups via cloud query so we add yc_mdb_postgresql_backups table which is fill in using BackupService API. I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=ru. --- Pull Request resolved: #43 Co-authored-by: dbeltukov <dbeltukov@yandex-team.com> commit_hash:dd655568f1169f4c5ed4a4184cdfc6fe7e41b710
1 parent 3dd77f6 commit b8fadf2

File tree

5 files changed

+66
-1
lines changed

5 files changed

+66
-1
lines changed

.mapping.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
"docs/tables/yc_mdb_opensearch_auth_settings.md":"security/cloudquery/cq-source-yc/docs/tables/yc_mdb_opensearch_auth_settings.md",
8383
"docs/tables/yc_mdb_opensearch_clusters.md":"security/cloudquery/cq-source-yc/docs/tables/yc_mdb_opensearch_clusters.md",
8484
"docs/tables/yc_mdb_opensearch_hosts.md":"security/cloudquery/cq-source-yc/docs/tables/yc_mdb_opensearch_hosts.md",
85+
"docs/tables/yc_mdb_postgresql_backups.md":"security/cloudquery/cq-source-yc/docs/tables/yc_mdb_postgresql_backups.md",
8586
"docs/tables/yc_mdb_postgresql_clusters.md":"security/cloudquery/cq-source-yc/docs/tables/yc_mdb_postgresql_clusters.md",
8687
"docs/tables/yc_mdb_postgresql_databases.md":"security/cloudquery/cq-source-yc/docs/tables/yc_mdb_postgresql_databases.md",
8788
"docs/tables/yc_mdb_postgresql_hosts.md":"security/cloudquery/cq-source-yc/docs/tables/yc_mdb_postgresql_hosts.md",
@@ -178,6 +179,7 @@
178179
"resources/mdb/opensearch_auth_settings.go":"security/cloudquery/cq-source-yc/resources/mdb/opensearch_auth_settings.go",
179180
"resources/mdb/opensearch_clusters.go":"security/cloudquery/cq-source-yc/resources/mdb/opensearch_clusters.go",
180181
"resources/mdb/opensearch_hosts.go":"security/cloudquery/cq-source-yc/resources/mdb/opensearch_hosts.go",
182+
"resources/mdb/postgresql_backups.go":"security/cloudquery/cq-source-yc/resources/mdb/postgresql_backups.go",
181183
"resources/mdb/postgresql_clusters.go":"security/cloudquery/cq-source-yc/resources/mdb/postgresql_clusters.go",
182184
"resources/mdb/postgresql_databases.go":"security/cloudquery/cq-source-yc/resources/mdb/postgresql_databases.go",
183185
"resources/mdb/postgresql_hosts.go":"security/cloudquery/cq-source-yc/resources/mdb/postgresql_hosts.go",

docs/tables/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
- [yc_mdb_postgresql_databases](yc_mdb_postgresql_databases.md)
6363
- [yc_mdb_postgresql_hosts](yc_mdb_postgresql_hosts.md)
6464
- [yc_mdb_postgresql_users](yc_mdb_postgresql_users.md)
65+
- [yc_mdb_postgresql_backups](yc_mdb_postgresql_backups.md)
6566
- [yc_mdb_redis_clusters](yc_mdb_redis_clusters.md)
6667
- [yc_mdb_redis_hosts](yc_mdb_redis_hosts.md)
6768
- [yc_nlb_balancers](yc_nlb_balancers.md)
@@ -87,4 +88,4 @@
8788
- [yc_vpc_security_groups](yc_vpc_security_groups.md)
8889
- [yc_vpc_subnets](yc_vpc_subnets.md)
8990
- [yc_ydb_databases](yc_ydb_databases.md)
90-
- [yc_access_bindings_ydb_databases](yc_access_bindings_ydb_databases.md)
91+
- [yc_access_bindings_ydb_databases](yc_access_bindings_ydb_databases.md)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Table: yc_mdb_postgresql_databases
2+
3+
This table shows data for YC Managed Service for Postgresql Backups.
4+
5+
https://yandex.cloud/ru/docs/managed-postgresql/api-ref/grpc/backup_service#Backup
6+
7+
The primary key for this table is **id**.
8+
9+
## Columns
10+
11+
| Name | Type |
12+
| ------------- | ------------- |
13+
|_cq_sync_time|`timestamp[us, tz=UTC]`|
14+
|_cq_source_name|`utf8`|
15+
|_cq_id|`uuid`|
16+
|_cq_parent_id|`uuid`|
17+
|cloud_id|`utf8`|
18+
|id (PK)|`utf8`|
19+
|folder_id|`utf8`|
20+
|created_at|`timestamp[us, tz=UTC]`|
21+
|source_cluster_id|`uuid`|
22+
|started_at|`timestamp[us, tz=UTC]`|
23+
|size|`int64`|
24+
|type|`utf8`|
25+
|method|`utf8`|
26+
|journal_size|`int64`|
27+
|status|`utf8`|

plugin/tables.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ func PluginAutoGeneratedTables() schema.Tables {
9696
mdb.MySQLClusters(),
9797
mdb.OpenSearchClusters(),
9898
mdb.PostgreSQLClusters(),
99+
mdb.PostgreSQLBackups(),
99100
mdb.RedisClusters(),
100101
nlb.Balancers(),
101102
nlb.TargetGroups(),
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package mdb
2+
3+
import (
4+
"context"
5+
6+
"github.com/cloudquery/plugin-sdk/v4/schema"
7+
"github.com/yandex-cloud/cq-source-yc/client"
8+
"github.com/yandex-cloud/go-genproto/yandex/cloud/mdb/postgresql/v1"
9+
)
10+
11+
func PostgreSQLBackups() *schema.Table {
12+
return &schema.Table{
13+
Name: "yc_mdb_postgresql_backups",
14+
Description: `https://yandex.cloud/ru/docs/managed-postgresql/api-ref/grpc/backup_service#Backup`,
15+
Multiplex: client.FolderMultiplex,
16+
Resolver: fetchPostgreSQLBackups,
17+
Transform: client.TransformWithStruct(&postgresql.Backup{}, client.PrimaryKeyIdTransformer),
18+
Columns: schema.ColumnList{
19+
client.CloudIdColumn,
20+
},
21+
}
22+
}
23+
24+
func fetchPostgreSQLBackups(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- interface{}) error {
25+
c := meta.(*client.Client)
26+
folderId := c.FolderId
27+
28+
it := c.SDK.MDB().PostgreSQL().Backup().BackupIterator(ctx, &postgresql.ListBackupsRequest{FolderId: folderId})
29+
for it.Next() {
30+
res <- it.Value()
31+
}
32+
33+
return it.Error()
34+
}

0 commit comments

Comments
 (0)