Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 1.23.2
go-version: "1.24.1"
- run: go generate ./...
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.60.2
version: v1.64.7
args: --verbose --timeout 20m --max-same-issues=30 --allow-parallel-runners
go-tidy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 1.23.2
go-version: "1.24.1"
- name: Verify tidy
run: |
go mod tidy
Expand All @@ -40,7 +40,7 @@ jobs:
fetch-depth: 0
- uses: actions/setup-go@v3
with:
go-version: 1.23.2
go-version: "1.24.1"
- uses: hashicorp/setup-terraform@v2
with:
terraform_version: "1.3.*"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ using Terraform Bytebase Provider to prepare those instances ready for applicati

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

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

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.20
1.0.21
30 changes: 3 additions & 27 deletions api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ type Client interface {
// Project
// GetProject gets the project by project full name.
GetProject(ctx context.Context, projectName string) (*v1pb.Project, error)
// ListProject list the projects,
ListProject(ctx context.Context, showDeleted bool) (*v1pb.ListProjectsResponse, error)
// ListProject list all projects,
ListProject(ctx context.Context, showDeleted bool) ([]*v1pb.Project, error)
// CreateProject creates the project.
CreateProject(ctx context.Context, projectID string, project *v1pb.Project) (*v1pb.Project, error)
// UpdateProject updates the project.
Expand All @@ -96,33 +96,9 @@ type Client interface {
// ParseExpression parse the expression string.
ParseExpression(ctx context.Context, expression string) (*v1alpha1.Expr, error)

// VCS Provider
// ListVCSProvider will returns all vcs providers.
ListVCSProvider(ctx context.Context) (*v1pb.ListVCSProvidersResponse, error)
// GetVCSProvider gets the vcs by full name.
GetVCSProvider(ctx context.Context, name string) (*v1pb.VCSProvider, error)
// CreateVCSProvider creates the vcs provider.
CreateVCSProvider(ctx context.Context, vcsID string, vcs *v1pb.VCSProvider) (*v1pb.VCSProvider, error)
// UpdateVCSProvider updates the vcs provider.
UpdateVCSProvider(ctx context.Context, patch *v1pb.VCSProvider, updateMasks []string) (*v1pb.VCSProvider, error)
// DeleteVCSProvider deletes the vcs provider.
DeleteVCSProvider(ctx context.Context, name string) error

// VCS Connector
// ListVCSConnector will returns all vcs connector in a project.
ListVCSConnector(ctx context.Context, projectName string) (*v1pb.ListVCSConnectorsResponse, error)
// GetVCSConnector gets the vcs connector by full name.
GetVCSConnector(ctx context.Context, name string) (*v1pb.VCSConnector, error)
// CreateVCSConnector creates the vcs connector in a project.
CreateVCSConnector(ctx context.Context, projectName, connectorID string, connector *v1pb.VCSConnector) (*v1pb.VCSConnector, error)
// UpdateVCSConnector updates the vcs connector.
UpdateVCSConnector(ctx context.Context, patch *v1pb.VCSConnector, updateMasks []string) (*v1pb.VCSConnector, error)
// DeleteVCSConnector deletes the vcs provider.
DeleteVCSConnector(ctx context.Context, name string) error

// User
// ListUser list all users.
ListUser(ctx context.Context, showDeleted bool) (*v1pb.ListUsersResponse, error)
ListUser(ctx context.Context, showDeleted bool) ([]*v1pb.User, error)
// CreateUser creates the user.
CreateUser(ctx context.Context, user *v1pb.User) (*v1pb.User, error)
// GetUser gets the user by name.
Expand Down
2 changes: 0 additions & 2 deletions api/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,4 @@ const (
ApprovalNodeTypeGroup ApprovalNodeType = "GROUP"
// ApprovalNodeTypeRole means the approval node is a role, the value should be role fullname.
ApprovalNodeTypeRole ApprovalNodeType = "ROLE"
// ApprovalNodeTypeExternalNodeID means the approval node is a external node, the value should be the node id.
ApprovalNodeTypeExternalNodeID ApprovalNodeType = "EXTERNAL_NODE"
)
50 changes: 47 additions & 3 deletions client/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import (
"context"
"fmt"
"net/http"
"net/url"
"strings"
"time"

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

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

// ListProject list the projects.
func (c *client) ListProject(ctx context.Context, showDeleted bool) (*v1pb.ListProjectsResponse, error) {
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("%s/%s/projects?showDeleted=%v", c.url, c.version, showDeleted), nil)
// ListProject list all projects.
func (c *client) ListProject(ctx context.Context, showDeleted bool) ([]*v1pb.Project, error) {
res := []*v1pb.Project{}
pageToken := ""
startTime := time.Now()

for {
startTimePerPage := time.Now()
resp, err := c.listProjectPerPage(ctx, showDeleted, pageToken, 500)
if err != nil {
return nil, err
}
res = append(res, resp.Projects...)
tflog.Debug(ctx, "[list project per page]", map[string]interface{}{
"count": len(resp.Projects),
"ms": time.Since(startTimePerPage).Milliseconds(),
})

pageToken = resp.NextPageToken
if pageToken == "" {
break
}
}

tflog.Debug(ctx, "[list project]", map[string]interface{}{
"total": len(res),
"ms": time.Since(startTime).Milliseconds(),
})

return res, nil
}

// listProjectPerPage list the projects.
func (c *client) listProjectPerPage(ctx context.Context, showDeleted bool, pageToken string, pageSize int) (*v1pb.ListProjectsResponse, error) {
requestURL := fmt.Sprintf(
"%s/%s/projects?showDeleted=%v&page_size=%d&page_token=%s",
c.url,
c.version,
showDeleted,
pageSize,
url.QueryEscape(pageToken),
)

req, err := http.NewRequestWithContext(ctx, "GET", requestURL, nil)
if err != nil {
return nil, err
}
Expand Down
48 changes: 46 additions & 2 deletions client/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,59 @@ import (
"context"
"fmt"
"net/http"
"net/url"
"strings"
"time"

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

// ListUser list all users.
func (c *client) ListUser(ctx context.Context, showDeleted bool) (*v1pb.ListUsersResponse, error) {
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("%s/%s/users?showDeleted=%v", c.url, c.version, showDeleted), nil)
func (c *client) ListUser(ctx context.Context, showDeleted bool) ([]*v1pb.User, error) {
res := []*v1pb.User{}
pageToken := ""
startTime := time.Now()

for {
startTimePerPage := time.Now()
resp, err := c.listUserPerPage(ctx, showDeleted, pageToken, 500)
if err != nil {
return nil, err
}
res = append(res, resp.Users...)
tflog.Debug(ctx, "[list user per page]", map[string]interface{}{
"count": len(resp.Users),
"ms": time.Since(startTimePerPage).Milliseconds(),
})

pageToken = resp.NextPageToken
if pageToken == "" {
break
}
}

tflog.Debug(ctx, "[list user]", map[string]interface{}{
"total": len(res),
"ms": time.Since(startTime).Milliseconds(),
})

return res, nil
}

// listUserPerPage list the users.
func (c *client) listUserPerPage(ctx context.Context, showDeleted bool, pageToken string, pageSize int) (*v1pb.ListUsersResponse, error) {
requestURL := fmt.Sprintf(
"%s/%s/users?showDeleted=%v&page_size=%d&page_token=%s",
c.url,
c.version,
showDeleted,
pageSize,
url.QueryEscape(pageToken),
)

req, err := http.NewRequestWithContext(ctx, "GET", requestURL, nil)
if err != nil {
return nil, err
}
Expand Down
Loading