Skip to content

Commit 16d97e7

Browse files
authored
chore: compatible with Bytebase 3.5.0 (#102)
* chore: compatible with 3.5.0 * chore: update test
1 parent 558d642 commit 16d97e7

Some content is hidden

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

54 files changed

+241
-1797
lines changed

.github/workflows/tests.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ jobs:
1313
- uses: actions/checkout@v3
1414
- uses: actions/setup-go@v3
1515
with:
16-
go-version: 1.23.2
16+
go-version: "1.24.1"
1717
- run: go generate ./...
1818
- name: golangci-lint
1919
uses: golangci/golangci-lint-action@v6
2020
with:
21-
version: v1.60.2
21+
version: v1.64.7
2222
args: --verbose --timeout 20m --max-same-issues=30 --allow-parallel-runners
2323
go-tidy:
2424
runs-on: ubuntu-latest
2525
steps:
2626
- uses: actions/checkout@v3
2727
- uses: actions/setup-go@v3
2828
with:
29-
go-version: 1.23.2
29+
go-version: "1.24.1"
3030
- name: Verify tidy
3131
run: |
3232
go mod tidy
@@ -40,7 +40,7 @@ jobs:
4040
fetch-depth: 0
4141
- uses: actions/setup-go@v3
4242
with:
43-
go-version: 1.23.2
43+
go-version: "1.24.1"
4444
- uses: hashicorp/setup-terraform@v2
4545
with:
4646
terraform_version: "1.3.*"

README.md

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

1818
- [Go](https://golang.org/doc/install) (1.19 or later)
1919
- [Terraform](https://developer.hashicorp.com/terraform/downloads?product_intent=terraform) (1.3.5 or later)
20-
- [Bytebase](https://github.com/bytebase/bytebase) (1.11.0 or later)
20+
- [Bytebase](https://github.com/bytebase/bytebase) (3.5.0 or later)
2121

2222
> 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`.
2323

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.20
1+
1.0.21

api/client.go

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ type Client interface {
6969
// Project
7070
// GetProject gets the project by project full name.
7171
GetProject(ctx context.Context, projectName string) (*v1pb.Project, error)
72-
// ListProject list the projects,
73-
ListProject(ctx context.Context, showDeleted bool) (*v1pb.ListProjectsResponse, error)
72+
// ListProject list all projects,
73+
ListProject(ctx context.Context, showDeleted bool) ([]*v1pb.Project, error)
7474
// CreateProject creates the project.
7575
CreateProject(ctx context.Context, projectID string, project *v1pb.Project) (*v1pb.Project, error)
7676
// UpdateProject updates the project.
@@ -96,33 +96,9 @@ type Client interface {
9696
// ParseExpression parse the expression string.
9797
ParseExpression(ctx context.Context, expression string) (*v1alpha1.Expr, error)
9898

99-
// VCS Provider
100-
// ListVCSProvider will returns all vcs providers.
101-
ListVCSProvider(ctx context.Context) (*v1pb.ListVCSProvidersResponse, error)
102-
// GetVCSProvider gets the vcs by full name.
103-
GetVCSProvider(ctx context.Context, name string) (*v1pb.VCSProvider, error)
104-
// CreateVCSProvider creates the vcs provider.
105-
CreateVCSProvider(ctx context.Context, vcsID string, vcs *v1pb.VCSProvider) (*v1pb.VCSProvider, error)
106-
// UpdateVCSProvider updates the vcs provider.
107-
UpdateVCSProvider(ctx context.Context, patch *v1pb.VCSProvider, updateMasks []string) (*v1pb.VCSProvider, error)
108-
// DeleteVCSProvider deletes the vcs provider.
109-
DeleteVCSProvider(ctx context.Context, name string) error
110-
111-
// VCS Connector
112-
// ListVCSConnector will returns all vcs connector in a project.
113-
ListVCSConnector(ctx context.Context, projectName string) (*v1pb.ListVCSConnectorsResponse, error)
114-
// GetVCSConnector gets the vcs connector by full name.
115-
GetVCSConnector(ctx context.Context, name string) (*v1pb.VCSConnector, error)
116-
// CreateVCSConnector creates the vcs connector in a project.
117-
CreateVCSConnector(ctx context.Context, projectName, connectorID string, connector *v1pb.VCSConnector) (*v1pb.VCSConnector, error)
118-
// UpdateVCSConnector updates the vcs connector.
119-
UpdateVCSConnector(ctx context.Context, patch *v1pb.VCSConnector, updateMasks []string) (*v1pb.VCSConnector, error)
120-
// DeleteVCSConnector deletes the vcs provider.
121-
DeleteVCSConnector(ctx context.Context, name string) error
122-
12399
// User
124100
// ListUser list all users.
125-
ListUser(ctx context.Context, showDeleted bool) (*v1pb.ListUsersResponse, error)
101+
ListUser(ctx context.Context, showDeleted bool) ([]*v1pb.User, error)
126102
// CreateUser creates the user.
127103
CreateUser(ctx context.Context, user *v1pb.User) (*v1pb.User, error)
128104
// GetUser gets the user by name.

api/setting.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,4 @@ const (
5050
ApprovalNodeTypeGroup ApprovalNodeType = "GROUP"
5151
// ApprovalNodeTypeRole means the approval node is a role, the value should be role fullname.
5252
ApprovalNodeTypeRole ApprovalNodeType = "ROLE"
53-
// ApprovalNodeTypeExternalNodeID means the approval node is a external node, the value should be the node id.
54-
ApprovalNodeTypeExternalNodeID ApprovalNodeType = "EXTERNAL_NODE"
5553
)

client/project.go

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ import (
44
"context"
55
"fmt"
66
"net/http"
7+
"net/url"
78
"strings"
9+
"time"
810

911
v1pb "github.com/bytebase/bytebase/proto/generated-go/v1"
12+
"github.com/hashicorp/terraform-plugin-log/tflog"
1013
"google.golang.org/protobuf/encoding/protojson"
1114
)
1215

@@ -66,9 +69,50 @@ func (c *client) SetProjectIAMPolicy(ctx context.Context, projectName string, up
6669
return &res, nil
6770
}
6871

69-
// ListProject list the projects.
70-
func (c *client) ListProject(ctx context.Context, showDeleted bool) (*v1pb.ListProjectsResponse, error) {
71-
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("%s/%s/projects?showDeleted=%v", c.url, c.version, showDeleted), nil)
72+
// ListProject list all projects.
73+
func (c *client) ListProject(ctx context.Context, showDeleted bool) ([]*v1pb.Project, error) {
74+
res := []*v1pb.Project{}
75+
pageToken := ""
76+
startTime := time.Now()
77+
78+
for {
79+
startTimePerPage := time.Now()
80+
resp, err := c.listProjectPerPage(ctx, showDeleted, pageToken, 500)
81+
if err != nil {
82+
return nil, err
83+
}
84+
res = append(res, resp.Projects...)
85+
tflog.Debug(ctx, "[list project per page]", map[string]interface{}{
86+
"count": len(resp.Projects),
87+
"ms": time.Since(startTimePerPage).Milliseconds(),
88+
})
89+
90+
pageToken = resp.NextPageToken
91+
if pageToken == "" {
92+
break
93+
}
94+
}
95+
96+
tflog.Debug(ctx, "[list project]", map[string]interface{}{
97+
"total": len(res),
98+
"ms": time.Since(startTime).Milliseconds(),
99+
})
100+
101+
return res, nil
102+
}
103+
104+
// listProjectPerPage list the projects.
105+
func (c *client) listProjectPerPage(ctx context.Context, showDeleted bool, pageToken string, pageSize int) (*v1pb.ListProjectsResponse, error) {
106+
requestURL := fmt.Sprintf(
107+
"%s/%s/projects?showDeleted=%v&page_size=%d&page_token=%s",
108+
c.url,
109+
c.version,
110+
showDeleted,
111+
pageSize,
112+
url.QueryEscape(pageToken),
113+
)
114+
115+
req, err := http.NewRequestWithContext(ctx, "GET", requestURL, nil)
72116
if err != nil {
73117
return nil, err
74118
}

client/user.go

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,59 @@ import (
44
"context"
55
"fmt"
66
"net/http"
7+
"net/url"
78
"strings"
9+
"time"
810

911
v1pb "github.com/bytebase/bytebase/proto/generated-go/v1"
12+
"github.com/hashicorp/terraform-plugin-log/tflog"
1013
"google.golang.org/protobuf/encoding/protojson"
1114
)
1215

1316
// ListUser list all users.
14-
func (c *client) ListUser(ctx context.Context, showDeleted bool) (*v1pb.ListUsersResponse, error) {
15-
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("%s/%s/users?showDeleted=%v", c.url, c.version, showDeleted), nil)
17+
func (c *client) ListUser(ctx context.Context, showDeleted bool) ([]*v1pb.User, error) {
18+
res := []*v1pb.User{}
19+
pageToken := ""
20+
startTime := time.Now()
21+
22+
for {
23+
startTimePerPage := time.Now()
24+
resp, err := c.listUserPerPage(ctx, showDeleted, pageToken, 500)
25+
if err != nil {
26+
return nil, err
27+
}
28+
res = append(res, resp.Users...)
29+
tflog.Debug(ctx, "[list user per page]", map[string]interface{}{
30+
"count": len(resp.Users),
31+
"ms": time.Since(startTimePerPage).Milliseconds(),
32+
})
33+
34+
pageToken = resp.NextPageToken
35+
if pageToken == "" {
36+
break
37+
}
38+
}
39+
40+
tflog.Debug(ctx, "[list user]", map[string]interface{}{
41+
"total": len(res),
42+
"ms": time.Since(startTime).Milliseconds(),
43+
})
44+
45+
return res, nil
46+
}
47+
48+
// listUserPerPage list the users.
49+
func (c *client) listUserPerPage(ctx context.Context, showDeleted bool, pageToken string, pageSize int) (*v1pb.ListUsersResponse, error) {
50+
requestURL := fmt.Sprintf(
51+
"%s/%s/users?showDeleted=%v&page_size=%d&page_token=%s",
52+
c.url,
53+
c.version,
54+
showDeleted,
55+
pageSize,
56+
url.QueryEscape(pageToken),
57+
)
58+
59+
req, err := http.NewRequestWithContext(ctx, "GET", requestURL, nil)
1660
if err != nil {
1761
return nil, err
1862
}

0 commit comments

Comments
 (0)