Skip to content

Commit 3177fcd

Browse files
authored
chore: several updates (#92)
* chore: use set for unordered collection * chore: update doc * fix: list all databases in the project * chore: update * fix: lint * chore: add databases for instance * chore: more error log * chore: update * chore: update
1 parent 2ded883 commit 3177fcd

28 files changed

+365
-121
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.13
1+
1.0.14

client/database.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import (
66
"net/http"
77
"net/url"
88
"strings"
9+
"time"
910

1011
v1pb "github.com/bytebase/bytebase/proto/generated-go/v1"
12+
"github.com/hashicorp/terraform-plugin-log/tflog"
1113
"google.golang.org/protobuf/encoding/protojson"
1214
)
1315

@@ -27,32 +29,44 @@ func (c *client) GetDatabase(ctx context.Context, databaseName string) (*v1pb.Da
2729
}
2830

2931
// ListDatabase list all databases.
30-
func (c *client) ListDatabase(ctx context.Context, instanceID, filter string) ([]*v1pb.Database, error) {
32+
func (c *client) ListDatabase(ctx context.Context, parent, filter string) ([]*v1pb.Database, error) {
3133
res := []*v1pb.Database{}
3234
pageToken := ""
35+
startTime := time.Now()
3336

3437
for {
35-
resp, err := c.listDatabasePerPage(ctx, instanceID, filter, pageToken, 500)
38+
startTimePerPage := time.Now()
39+
resp, err := c.listDatabasePerPage(ctx, parent, filter, pageToken, 500)
3640
if err != nil {
3741
return nil, err
3842
}
3943
res = append(res, resp.Databases...)
44+
tflog.Debug(ctx, "[list database per page]", map[string]interface{}{
45+
"count": len(resp.Databases),
46+
"ms": time.Since(startTimePerPage).Milliseconds(),
47+
})
48+
4049
pageToken = resp.NextPageToken
4150
if pageToken == "" {
4251
break
4352
}
4453
}
4554

55+
tflog.Debug(ctx, "[list database]", map[string]interface{}{
56+
"total": len(res),
57+
"ms": time.Since(startTime).Milliseconds(),
58+
})
59+
4660
return res, nil
4761
}
4862

4963
// listDatabasePerPage list the databases.
50-
func (c *client) listDatabasePerPage(ctx context.Context, instanceID, filter, pageToken string, pageSize int) (*v1pb.ListDatabasesResponse, error) {
64+
func (c *client) listDatabasePerPage(ctx context.Context, parent, filter, pageToken string, pageSize int) (*v1pb.ListDatabasesResponse, error) {
5165
requestURL := fmt.Sprintf(
52-
"%s/%s/instances/%s/databases?filter=%s&page_size=%d&page_token=%s",
66+
"%s/%s/%s/databases?filter=%s&page_size=%d&page_token=%s",
5367
c.url,
5468
c.version,
55-
instanceID,
69+
parent,
5670
url.QueryEscape(filter),
5771
pageSize,
5872
pageToken,

examples/environments/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
terraform {
33
required_providers {
44
bytebase = {
5-
version = "1.0.9"
5+
version = "1.0.14"
66
# For local development, please use "terraform.local/bytebase/bytebase" instead
77
source = "registry.terraform.io/bytebase/bytebase"
88
}

examples/groups/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
terraform {
22
required_providers {
33
bytebase = {
4-
version = "1.0.9"
4+
version = "1.0.14"
55
# For local development, please use "terraform.local/bytebase/bytebase" instead
66
source = "registry.terraform.io/bytebase/bytebase"
77
}

examples/instances/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
terraform {
33
required_providers {
44
bytebase = {
5-
version = "1.0.9"
5+
version = "1.0.14"
66
# For local development, please use "terraform.local/bytebase/bytebase" instead
77
source = "registry.terraform.io/bytebase/bytebase"
88
}

examples/policies/main.tf

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
terraform {
22
required_providers {
33
bytebase = {
4-
version = "1.0.9"
4+
version = "1.0.14"
55
# For local development, please use "terraform.local/bytebase/bytebase" instead
66
source = "registry.terraform.io/bytebase/bytebase"
77
}
@@ -25,3 +25,11 @@ data "bytebase_policy" "masking_exception_policy" {
2525
output "masking_exception_policy" {
2626
value = data.bytebase_policy.masking_exception_policy
2727
}
28+
29+
data "bytebase_policy" "global_masking_policy" {
30+
type = "MASKING_RULE"
31+
}
32+
33+
output "global_masking_policy" {
34+
value = data.bytebase_policy.global_masking_policy
35+
}

examples/projects/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
terraform {
33
required_providers {
44
bytebase = {
5-
version = "1.0.9"
5+
version = "1.0.14"
66
# For local development, please use "terraform.local/bytebase/bytebase" instead
77
source = "registry.terraform.io/bytebase/bytebase"
88
}

examples/settings/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
terraform {
22
required_providers {
33
bytebase = {
4-
version = "1.0.9"
4+
version = "1.0.14"
55
# For local development, please use "terraform.local/bytebase/bytebase" instead
66
source = "registry.terraform.io/bytebase/bytebase"
77
}

examples/setup/data_masking.tf

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,28 @@ resource "bytebase_policy" "masking_exception_policy" {
9696
}
9797
}
9898
}
99+
100+
resource "bytebase_policy" "global_masking_policy" {
101+
depends_on = [
102+
bytebase_instance.prod,
103+
bytebase_environment.test
104+
]
105+
106+
parent = ""
107+
type = "MASKING_RULE"
108+
enforce = true
109+
inherit_from_parent = false
110+
111+
global_masking_policy {
112+
rules {
113+
condition = "environment_id in [\"test\"]"
114+
id = "69df1d15-abe5-4bc9-be38-f2a4bef3f7e0"
115+
semantic_type = "bb.default-partial"
116+
}
117+
rules {
118+
condition = "instance_id in [\"prod-sample-instance\"]"
119+
id = "90adb734-0808-4c9f-b281-1f76f7a1a29a"
120+
semantic_type = "bb.default"
121+
}
122+
}
123+
}

examples/setup/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
terraform {
22
required_providers {
33
bytebase = {
4-
version = "1.0.9"
4+
version = "1.0.14"
55
# For local development, please use "terraform.local/bytebase/bytebase" instead
66
source = "registry.terraform.io/bytebase/bytebase"
77
}

0 commit comments

Comments
 (0)