Skip to content

Commit 8930267

Browse files
authored
chore: upgrade proto deps, auto-resolve workspace parent, and release 3.16.0 (#173)
* chore: upgrade bytebase * chore: update * fix: lint
1 parent 9daeb5d commit 8930267

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+402
-161
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ using Terraform Bytebase Provider to prepare those instances ready for applicati
1515

1616
- [Go](https://golang.org/doc/install) (1.19 or later)
1717
- [Terraform](https://developer.hashicorp.com/terraform/downloads?product_intent=terraform) (1.3.5 or later)
18-
- [Bytebase](https://github.com/bytebase/bytebase) (3.15.0 or later)
18+
- [Bytebase](https://github.com/bytebase/bytebase) (3.16.0 or later)
1919

2020
> If you have problems running `terraform` in MacOS with Apple Silicon, you can following https://stackoverflow.com/questions/66281882/how-can-i-get-terraform-init-to-run-on-my-apple-silicon-macbook-pro-for-the-go and use the `tfenv`.
2121

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.15.2
1+
3.16.0

api/client.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,10 @@ type DatabaseFilter struct {
4444

4545
// UserFilter is the filter for list users API.
4646
type UserFilter struct {
47-
Name string
48-
Email string
49-
Project string
50-
UserTypes []v1pb.UserType
51-
State v1pb.State
47+
Name string
48+
Email string
49+
Project string
50+
State v1pb.State
5251
}
5352

5453
// GroupFilter is the filter for list group API.
@@ -59,6 +58,9 @@ type GroupFilter struct {
5958

6059
// Client is the API message for Bytebase OpenAPI client.
6160
type Client interface {
61+
// GetWorkspaceName returns the workspace resource name in "workspaces/{workspace-id}" format.
62+
GetWorkspaceName() string
63+
6264
// Instance
6365
// ListInstance will return instances.
6466
ListInstance(ctx context.Context, filter *InstanceFilter) ([]*v1pb.Instance, error)

client/client.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package client
33

44
import (
55
"context"
6+
"fmt"
67
"net/http"
78
"strings"
89
"time"
@@ -18,10 +19,12 @@ import (
1819

1920
// client is the API message for Bytebase API client.
2021
type client struct {
21-
url string
22-
client *http.Client
22+
url string
23+
workspaceName string
24+
client *http.Client
2325

2426
// Connect RPC clients
27+
actuatorClient bytebasev1connect.ActuatorServiceClient
2528
authClient bytebasev1connect.AuthServiceClient
2629
workspaceClient bytebasev1connect.WorkspaceServiceClient
2730
instanceClient bytebasev1connect.InstanceServiceClient
@@ -40,6 +43,11 @@ type client struct {
4043
workloadIdentityClient bytebasev1connect.WorkloadIdentityServiceClient
4144
}
4245

46+
// GetWorkspaceName returns the workspace resource name.
47+
func (c *client) GetWorkspaceName() string {
48+
return c.workspaceName
49+
}
50+
4351
// NewClient returns the new Bytebase API client.
4452
func NewClient(url, email, password string) (api.Client, error) {
4553
c := client{
@@ -55,7 +63,6 @@ func NewClient(url, email, password string) (api.Client, error) {
5563
interceptors := connect.WithInterceptors(authInt)
5664

5765
// Create auth client without token first
58-
// Try without WithGRPC first to see if it's a standard Connect/gRPC-Web service
5966
c.authClient = bytebasev1connect.NewAuthServiceClient(
6067
c.client,
6168
c.url,
@@ -75,6 +82,7 @@ func NewClient(url, email, password string) (api.Client, error) {
7582
authInt.token = loginResp.Msg.Token
7683

7784
// Initialize other clients with auth token
85+
c.actuatorClient = bytebasev1connect.NewActuatorServiceClient(c.client, c.url, interceptors)
7886
c.workspaceClient = bytebasev1connect.NewWorkspaceServiceClient(c.client, c.url, interceptors)
7987
c.instanceClient = bytebasev1connect.NewInstanceServiceClient(c.client, c.url, interceptors)
8088
c.databaseClient = bytebasev1connect.NewDatabaseServiceClient(c.client, c.url, interceptors)
@@ -91,5 +99,12 @@ func NewClient(url, email, password string) (api.Client, error) {
9199
c.serviceAccountClient = bytebasev1connect.NewServiceAccountServiceClient(c.client, c.url, interceptors)
92100
c.workloadIdentityClient = bytebasev1connect.NewWorkloadIdentityServiceClient(c.client, c.url, interceptors)
93101

102+
// Fetch workspace ID from actuator
103+
actuatorResp, err := c.actuatorClient.GetActuatorInfo(context.Background(), connect.NewRequest(&v1pb.GetActuatorInfoRequest{}))
104+
if err != nil {
105+
return nil, errors.Wrapf(err, "failed to get actuator info")
106+
}
107+
c.workspaceName = fmt.Sprintf("workspaces/%s", actuatorResp.Msg.GetWorkspaceId())
108+
94109
return &c, nil
95110
}

client/user.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,6 @@ func buildUserFilter(filter *api.UserFilter) string {
2727
if v := filter.Project; v != "" {
2828
params = append(params, fmt.Sprintf(`project == "%s"`, v))
2929
}
30-
if v := filter.UserTypes; len(v) > 0 {
31-
userTypes := []string{}
32-
for _, t := range v {
33-
userTypes = append(userTypes, fmt.Sprintf(`"%s"`, t.String()))
34-
}
35-
params = append(params, fmt.Sprintf(`user_type in [%s]`, strings.Join(userTypes, ", ")))
36-
}
3730
if filter.State == v1pb.State_DELETED {
3831
params = append(params, fmt.Sprintf(`state == "%s"`, filter.State.String()))
3932
}

client/workspace.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func (c *client) GetWorkspaceIAMPolicy(ctx context.Context) (*v1pb.IamPolicy, er
1515
}
1616

1717
req := connect.NewRequest(&v1pb.GetIamPolicyRequest{
18-
Resource: "workspaces/-",
18+
Resource: c.workspaceName,
1919
})
2020

2121
resp, err := c.workspaceClient.GetIamPolicy(ctx, req)
@@ -34,7 +34,7 @@ func (c *client) SetWorkspaceIAMPolicy(ctx context.Context, setIamPolicyRequest
3434

3535
// Ensure the resource is set correctly
3636
if setIamPolicyRequest.Resource == "" {
37-
setIamPolicyRequest.Resource = "workspaces/-"
37+
setIamPolicyRequest.Resource = c.workspaceName
3838
}
3939

4040
req := connect.NewRequest(setIamPolicyRequest)

docs/data-sources/database_list.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,14 @@ The database data source list.
1515
<!-- schema generated by tfplugindocs -->
1616
## Schema
1717

18-
### Required
19-
20-
- `parent` (String)
21-
2218
### Optional
2319

2420
- `engines` (Set of String) Filter databases by engines.
2521
- `environment` (String) The environment full name. Filter databases by environment.
2622
- `exclude_unassigned` (Boolean) If not include unassigned databases in the response.
2723
- `instance` (String) The instance full name. Filter databases by instance.
2824
- `labels` (Map of String) Filter databases by labels
25+
- `parent` (String) The parent resource. Format: workspaces/{workspace id}, instances/{instance id}, or projects/{project id}. Defaults to the workspace if not specified.
2926
- `project` (String) The project full name. Filter databases by project.
3027
- `query` (String) Filter databases by name with wildcard
3128

docs/data-sources/iam_policy.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,10 @@ The IAM policy data source.
1515
<!-- schema generated by tfplugindocs -->
1616
## Schema
1717

18-
### Required
19-
20-
- `parent` (String) The IAM policy parent name for the policy, support "projects/{resource id}" or "workspaces/-"
21-
2218
### Optional
2319

2420
- `iam_policy` (Block List, Max: 1) (see [below for nested schema](#nestedblock--iam_policy))
21+
- `parent` (String) The IAM policy parent name for the policy, support "projects/{resource id}" or "workspaces/{workspace id}". Defaults to the workspace if not specified.
2522

2623
### Read-Only
2724

docs/data-sources/policy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ The policy data source.
1717

1818
### Required
1919

20-
- `parent` (String) The policy parent name for the policy, support projects/{resource id}, environments/{resource id}, instances/{resource id}, or instances/{resource id}/databases/{database name}
2120
- `type` (String) The policy type.
2221

2322
### Optional
2423

2524
- `global_masking_policy` (Block List, Max: 1) (see [below for nested schema](#nestedblock--global_masking_policy))
2625
- `masking_exemption_policy` (Block List, Max: 1) (see [below for nested schema](#nestedblock--masking_exemption_policy))
26+
- `parent` (String) The policy parent name for the policy, support workspaces/{workspace id}, projects/{resource id}, environments/{resource id}, instances/{resource id}, or instances/{resource id}/databases/{database name}. Defaults to the workspace if not specified.
2727
- `query_data_policy` (Block List, Max: 1) The policy for query data (see [below for nested schema](#nestedblock--query_data_policy))
2828
- `rollout_policy` (Block List, Max: 1) Control issue rollout. Learn more: https://docs.bytebase.com/administration/environment-policy/rollout-policy (see [below for nested schema](#nestedblock--rollout_policy))
2929

docs/data-sources/policy_list.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The policy data source list.
1717

1818
### Optional
1919

20-
- `parent` (String) The policy parent name for the policy, support projects/{resource id}, environments/{resource id}, instances/{resource id}, or instances/{resource id}/databases/{database name}
20+
- `parent` (String) The policy parent name for the policy, support workspaces/{workspace id}, projects/{resource id}, environments/{resource id}, instances/{resource id}, or instances/{resource id}/databases/{database name}. Defaults to the workspace if not specified.
2121

2222
### Read-Only
2323

0 commit comments

Comments
 (0)