Skip to content

Commit 2ac2bae

Browse files
authored
chore: support masking/masking exception policy (#79)
* refactor: use protocol api * fix: go mod * chore: update * chore: update * chore: go version * fix: test * chore: golang lint * chore: support approval setting * chore: support approval flow * chore: update * fix: go mod tidy * fix: lint * chore: update * chore: update * chore: update * fix: lint * chore: policy and setting * chore: update * chore: update docs
1 parent cb288ca commit 2ac2bae

29 files changed

+971
-936
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ terraform destory
7373

7474
> This will generate the doc template in the `docs` folder
7575
>
76-
> Check https://github.com/hashicorp/terraform-plugin-docs for details.
76+
> Check https://github.com/hashicorp/terraform-plugin-docs and https://github.com/hashicorp/terraform-plugin-docs/issues/141 for details.
7777
7878
```bash
79-
go run github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs --provider-name=terraform-provider-bytebase
79+
GOOS=darwin GOARCH=amd64 go run github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs --provider-name=terraform-provider-bytebase
8080
```
8181

8282
## Release

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.3
1+
1.0.4

api/client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ type Client interface {
4545

4646
// Policy
4747
// ListPolicies lists policies in a specific resource.
48-
ListPolicies(ctx context.Context, find *PolicyFindMessage) (*ListPolicyMessage, error)
48+
ListPolicies(ctx context.Context, parent string) (*v1pb.ListPoliciesResponse, error)
4949
// GetPolicy gets a policy in a specific resource.
50-
GetPolicy(ctx context.Context, policyName string) (*PolicyMessage, error)
50+
GetPolicy(ctx context.Context, policyName string) (*v1pb.Policy, error)
5151
// UpsertPolicy creates or updates the policy.
52-
UpsertPolicy(ctx context.Context, patch *PolicyPatchMessage) (*PolicyMessage, error)
52+
UpsertPolicy(ctx context.Context, patch *v1pb.Policy, updateMasks []string) (*v1pb.Policy, error)
5353
// DeletePolicy deletes the policy.
5454
DeletePolicy(ctx context.Context, policyName string) error
5555

api/deployment.go

Lines changed: 0 additions & 19 deletions
This file was deleted.

api/policy.go

Lines changed: 0 additions & 130 deletions
This file was deleted.

client/policy.go

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,21 @@ package client
22

33
import (
44
"context"
5-
"encoding/json"
65
"fmt"
76
"net/http"
87
"strings"
98

10-
"github.com/pkg/errors"
11-
12-
"github.com/bytebase/terraform-provider-bytebase/api"
9+
v1pb "github.com/bytebase/bytebase/proto/generated-go/v1"
10+
"google.golang.org/protobuf/encoding/protojson"
1311
)
1412

1513
// ListPolicies lists policies in a specific resource.
16-
func (c *client) ListPolicies(ctx context.Context, find *api.PolicyFindMessage) (*api.ListPolicyMessage, error) {
17-
if find.Type != nil {
18-
return nil, errors.Errorf("invalid request, list policies cannot specific the policy type")
19-
}
20-
14+
func (c *client) ListPolicies(ctx context.Context, parent string) (*v1pb.ListPoliciesResponse, error) {
2115
var url string
22-
if find.Parent == "" {
16+
if parent == "" {
2317
url = fmt.Sprintf("%s/%s/policies", c.url, c.version)
2418
} else {
25-
url = fmt.Sprintf("%s/%s/%s/policies", c.url, c.version, find.Parent)
19+
url = fmt.Sprintf("%s/%s/%s/policies", c.url, c.version, parent)
2620
}
2721
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
2822
if err != nil {
@@ -34,16 +28,16 @@ func (c *client) ListPolicies(ctx context.Context, find *api.PolicyFindMessage)
3428
return nil, err
3529
}
3630

37-
var res api.ListPolicyMessage
38-
if err := json.Unmarshal(body, &res); err != nil {
31+
var res v1pb.ListPoliciesResponse
32+
if err := ProtojsonUnmarshaler.Unmarshal(body, &res); err != nil {
3933
return nil, err
4034
}
4135

4236
return &res, nil
4337
}
4438

4539
// GetPolicy gets a policy in a specific resource.
46-
func (c *client) GetPolicy(ctx context.Context, policyName string) (*api.PolicyMessage, error) {
40+
func (c *client) GetPolicy(ctx context.Context, policyName string) (*v1pb.Policy, error) {
4741
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("%s/%s/%s", c.url, c.version, policyName), nil)
4842
if err != nil {
4943
return nil, err
@@ -54,33 +48,22 @@ func (c *client) GetPolicy(ctx context.Context, policyName string) (*api.PolicyM
5448
return nil, err
5549
}
5650

57-
var res api.PolicyMessage
58-
if err := json.Unmarshal(body, &res); err != nil {
51+
var res v1pb.Policy
52+
if err := ProtojsonUnmarshaler.Unmarshal(body, &res); err != nil {
5953
return nil, err
6054
}
6155

6256
return &res, nil
6357
}
6458

6559
// UpsertPolicy creates or updates the policy.
66-
func (c *client) UpsertPolicy(ctx context.Context, patch *api.PolicyPatchMessage) (*api.PolicyMessage, error) {
67-
payload, err := json.Marshal(patch)
60+
func (c *client) UpsertPolicy(ctx context.Context, policy *v1pb.Policy, updateMasks []string) (*v1pb.Policy, error) {
61+
payload, err := protojson.Marshal(policy)
6862
if err != nil {
6963
return nil, err
7064
}
7165

72-
paths := []string{}
73-
if patch.InheritFromParent != nil {
74-
paths = append(paths, "inherit_from_parent")
75-
}
76-
if patch.DeploymentApprovalPolicy != nil ||
77-
patch.BackupPlanPolicy != nil ||
78-
patch.SensitiveDataPolicy != nil ||
79-
patch.AccessControlPolicy != nil {
80-
paths = append(paths, "payload")
81-
}
82-
83-
req, err := http.NewRequestWithContext(ctx, "PATCH", fmt.Sprintf("%s/%s/%s?allow_missing=true&update_mask=%s", c.url, c.version, patch.Name, strings.Join(paths, ",")), strings.NewReader(string(payload)))
66+
req, err := http.NewRequestWithContext(ctx, "PATCH", fmt.Sprintf("%s/%s/%s?allow_missing=true&update_mask=%s", c.url, c.version, policy.Name, strings.Join(updateMasks, ",")), strings.NewReader(string(payload)))
8467
if err != nil {
8568
return nil, err
8669
}
@@ -90,8 +73,8 @@ func (c *client) UpsertPolicy(ctx context.Context, patch *api.PolicyPatchMessage
9073
return nil, err
9174
}
9275

93-
var res api.PolicyMessage
94-
if err := json.Unmarshal(body, &res); err != nil {
76+
var res v1pb.Policy
77+
if err := ProtojsonUnmarshaler.Unmarshal(body, &res); err != nil {
9578
return nil, err
9679
}
9780

docs/data-sources/instance.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ Read-Only:
3737
- `database` (String)
3838
- `host` (String)
3939
- `id` (String)
40+
- `password` (String)
4041
- `port` (String)
42+
- `ssl_ca` (String)
43+
- `ssl_cert` (String)
44+
- `ssl_key` (String)
4145
- `type` (String)
4246
- `username` (String)
4347

docs/data-sources/instance_list.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ Read-Only:
4545
- `database` (String)
4646
- `host` (String)
4747
- `id` (String)
48+
- `password` (String)
4849
- `port` (String)
50+
- `ssl_ca` (String)
51+
- `ssl_cert` (String)
52+
- `ssl_key` (String)
4953
- `type` (String)
5054
- `username` (String)
5155

0 commit comments

Comments
 (0)