Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
173 changes: 0 additions & 173 deletions client/vcs.go

This file was deleted.

2 changes: 1 addition & 1 deletion docs/data-sources/database.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ The database data source.
- `labels` (Map of String) The deployment and policy control labels.
- `project` (String) The project full name for the database in projects/{project} format.
- `schema_version` (String) The version of database schema.
- `state` (String) The existence of a database.
- `successful_sync_time` (String) The latest synchronization time.
- `sync_state` (String) The existence of a database on latest sync.

<a id="nestedatt--catalog"></a>
### Nested Schema for `catalog`
Expand Down
2 changes: 1 addition & 1 deletion docs/data-sources/database_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Read-Only:
- `name` (String)
- `project` (String)
- `schema_version` (String)
- `state` (String)
- `successful_sync_time` (String)
- `sync_state` (String)


1 change: 0 additions & 1 deletion docs/data-sources/project.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ The project data source.
- `postgres_database_tenant_mode` (Boolean) Whether to enable the database tenant mode for PostgreSQL. If enabled, the issue will be created with the pre-appended "set role <db_owner>" statement.
- `skip_backup_errors` (Boolean) Whether to skip backup errors and continue the data migration.
- `title` (String) The project title.
- `workflow` (String) The project workflow.

<a id="nestedatt--members"></a>
### Nested Schema for `members`
Expand Down
Loading
Loading