Skip to content

Commit 0e0054c

Browse files
authored
chore: support set roles for user in workspace level & support group (#82)
* chore: support set roles for user in workspace level * fix: lint * fix: test * chore: support group * fix: test * fix: test * chore: update examples
1 parent be77d5c commit 0e0054c

Some content is hidden

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

45 files changed

+1586
-328
lines changed

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.4
1+
1.0.5

api/client.go

+20-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ type Client interface {
7676
// GetProjectIAMPolicy gets the project IAM policy by project full name.
7777
GetProjectIAMPolicy(ctx context.Context, projectName string) (*v1pb.IamPolicy, error)
7878
// SetProjectIAMPolicy sets the project IAM policy.
79-
SetProjectIAMPolicy(ctx context.Context, projectName string, iamPolicy *v1pb.IamPolicy) (*v1pb.IamPolicy, error)
79+
SetProjectIAMPolicy(ctx context.Context, projectName string, update *v1pb.SetIamPolicyRequest) (*v1pb.IamPolicy, error)
8080

8181
// Setting
8282
// ListSettings lists all settings.
@@ -98,7 +98,7 @@ type Client interface {
9898
// CreateVCSProvider creates the vcs provider.
9999
CreateVCSProvider(ctx context.Context, vcsID string, vcs *v1pb.VCSProvider) (*v1pb.VCSProvider, error)
100100
// UpdateVCSProvider updates the vcs provider.
101-
UpdateVCSProvider(ctx context.Context, patch *v1pb.VCSProvider, updateMasks []string) (*v1pb.VCSConnector, error)
101+
UpdateVCSProvider(ctx context.Context, patch *v1pb.VCSProvider, updateMasks []string) (*v1pb.VCSProvider, error)
102102
// DeleteVCSProvider deletes the vcs provider.
103103
DeleteVCSProvider(ctx context.Context, name string) error
104104

@@ -127,4 +127,22 @@ type Client interface {
127127
DeleteUser(ctx context.Context, userName string) error
128128
// UndeleteUser undeletes the user by name.
129129
UndeleteUser(ctx context.Context, userName string) (*v1pb.User, error)
130+
131+
// Group
132+
// ListGroup list all groups.
133+
ListGroup(ctx context.Context) (*v1pb.ListGroupsResponse, error)
134+
// CreateGroup creates the group.
135+
CreateGroup(ctx context.Context, email string, group *v1pb.Group) (*v1pb.Group, error)
136+
// GetGroup gets the group by name.
137+
GetGroup(ctx context.Context, name string) (*v1pb.Group, error)
138+
// UpdateGroup updates the group.
139+
UpdateGroup(ctx context.Context, patch *v1pb.Group, updateMasks []string) (*v1pb.Group, error)
140+
// DeleteGroup deletes the group by name.
141+
DeleteGroup(ctx context.Context, name string) error
142+
143+
// Workspace
144+
// GetWorkspaceIAMPolicy gets the workspace IAM policy.
145+
GetWorkspaceIAMPolicy(ctx context.Context) (*v1pb.IamPolicy, error)
146+
// SetWorkspaceIAMPolicy sets the workspace IAM policy.
147+
SetWorkspaceIAMPolicy(ctx context.Context, setIamPolicyRequest *v1pb.SetIamPolicyRequest) (*v1pb.IamPolicy, error)
130148
}

client/group.go

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package client
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"net/http"
7+
"strings"
8+
9+
v1pb "github.com/bytebase/bytebase/proto/generated-go/v1"
10+
"google.golang.org/protobuf/encoding/protojson"
11+
)
12+
13+
// ListGroup list all groups.
14+
func (c *client) ListGroup(ctx context.Context) (*v1pb.ListGroupsResponse, error) {
15+
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("%s/%s/groups", c.url, c.version), nil)
16+
if err != nil {
17+
return nil, err
18+
}
19+
20+
body, err := c.doRequest(req)
21+
if err != nil {
22+
return nil, err
23+
}
24+
25+
var res v1pb.ListGroupsResponse
26+
if err := ProtojsonUnmarshaler.Unmarshal(body, &res); err != nil {
27+
return nil, err
28+
}
29+
30+
return &res, nil
31+
}
32+
33+
// CreateGroup creates the group.
34+
func (c *client) CreateGroup(ctx context.Context, email string, group *v1pb.Group) (*v1pb.Group, error) {
35+
payload, err := protojson.Marshal(group)
36+
if err != nil {
37+
return nil, err
38+
}
39+
40+
req, err := http.NewRequestWithContext(ctx, "POST", fmt.Sprintf("%s/%s/groups?groupEmail=%s", c.url, c.version, email), strings.NewReader(string(payload)))
41+
42+
if err != nil {
43+
return nil, err
44+
}
45+
46+
body, err := c.doRequest(req)
47+
if err != nil {
48+
return nil, err
49+
}
50+
51+
var res v1pb.Group
52+
if err := ProtojsonUnmarshaler.Unmarshal(body, &res); err != nil {
53+
return nil, err
54+
}
55+
56+
return &res, nil
57+
}
58+
59+
// GetGroup gets the group by name.
60+
func (c *client) GetGroup(ctx context.Context, name string) (*v1pb.Group, error) {
61+
body, err := c.getResource(ctx, name)
62+
if err != nil {
63+
return nil, err
64+
}
65+
66+
var res v1pb.Group
67+
if err := ProtojsonUnmarshaler.Unmarshal(body, &res); err != nil {
68+
return nil, err
69+
}
70+
71+
return &res, nil
72+
}
73+
74+
// UpdateGroup updates the group.
75+
func (c *client) UpdateGroup(ctx context.Context, patch *v1pb.Group, updateMasks []string) (*v1pb.Group, error) {
76+
body, err := c.updateResource(ctx, patch.Name, patch, updateMasks, false /* allow missing = false*/)
77+
if err != nil {
78+
return nil, err
79+
}
80+
81+
var res v1pb.Group
82+
if err := ProtojsonUnmarshaler.Unmarshal(body, &res); err != nil {
83+
return nil, err
84+
}
85+
86+
return &res, nil
87+
}
88+
89+
// DeleteGroup deletes the group by name.
90+
func (c *client) DeleteGroup(ctx context.Context, name string) error {
91+
return c.deleteResource(ctx, name)
92+
}

client/project.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,8 @@ func (c *client) GetProjectIAMPolicy(ctx context.Context, projectName string) (*
4141
}
4242

4343
// SetProjectIAMPolicy sets the project IAM policy.
44-
func (c *client) SetProjectIAMPolicy(ctx context.Context, projectName string, iamPolicy *v1pb.IamPolicy) (*v1pb.IamPolicy, error) {
45-
payload, err := protojson.Marshal(&v1pb.SetIamPolicyRequest{
46-
Policy: iamPolicy,
47-
})
44+
func (c *client) SetProjectIAMPolicy(ctx context.Context, projectName string, update *v1pb.SetIamPolicyRequest) (*v1pb.IamPolicy, error) {
45+
payload, err := protojson.Marshal(update)
4846
if err != nil {
4947
return nil, err
5048
}

client/vcs.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ func (c *client) CreateVCSProvider(ctx context.Context, vcsID string, vcs *v1pb.
7272
}
7373

7474
// UpdateVCSProvider updates the vcs provider.
75-
func (c *client) UpdateVCSProvider(ctx context.Context, patch *v1pb.VCSProvider, updateMasks []string) (*v1pb.VCSConnector, error) {
75+
func (c *client) UpdateVCSProvider(ctx context.Context, patch *v1pb.VCSProvider, updateMasks []string) (*v1pb.VCSProvider, error) {
7676
body, err := c.updateResource(ctx, patch.Name, patch, updateMasks, false /* allow missing = false*/)
7777
if err != nil {
7878
return nil, err
7979
}
8080

81-
var res v1pb.VCSConnector
81+
var res v1pb.VCSProvider
8282
if err := ProtojsonUnmarshaler.Unmarshal(body, &res); err != nil {
8383
return nil, err
8484
}

client/workspace.go

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package client
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"net/http"
7+
"strings"
8+
9+
v1pb "github.com/bytebase/bytebase/proto/generated-go/v1"
10+
"google.golang.org/protobuf/encoding/protojson"
11+
)
12+
13+
// GetWorkspaceIAMPolicy gets the workspace IAM policy.
14+
func (c *client) GetWorkspaceIAMPolicy(ctx context.Context) (*v1pb.IamPolicy, error) {
15+
body, err := c.getResource(ctx, "workspaces/-:getIamPolicy")
16+
if err != nil {
17+
return nil, err
18+
}
19+
20+
var res v1pb.IamPolicy
21+
if err := ProtojsonUnmarshaler.Unmarshal(body, &res); err != nil {
22+
return nil, err
23+
}
24+
25+
return &res, nil
26+
}
27+
28+
// SetWorkspaceIAMPolicy sets the workspace IAM policy.
29+
func (c *client) SetWorkspaceIAMPolicy(ctx context.Context, setIamPolicyRequest *v1pb.SetIamPolicyRequest) (*v1pb.IamPolicy, error) {
30+
payload, err := protojson.Marshal(setIamPolicyRequest)
31+
if err != nil {
32+
return nil, err
33+
}
34+
35+
req, err := http.NewRequestWithContext(ctx, "POST", fmt.Sprintf("%s/%s/%s:setIamPolicy", c.url, c.version, "workspaces/-"), strings.NewReader(string(payload)))
36+
37+
if err != nil {
38+
return nil, err
39+
}
40+
41+
body, err := c.doRequest(req)
42+
if err != nil {
43+
return nil, err
44+
}
45+
46+
var res v1pb.IamPolicy
47+
if err := ProtojsonUnmarshaler.Unmarshal(body, &res); err != nil {
48+
return nil, err
49+
}
50+
51+
return &res, nil
52+
}

docs/data-sources/group.md

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "bytebase_group Data Source - terraform-provider-bytebase"
4+
subcategory: ""
5+
description: |-
6+
The group data source.
7+
---
8+
9+
# bytebase_group (Data Source)
10+
11+
The group data source.
12+
13+
14+
15+
<!-- schema generated by tfplugindocs -->
16+
## Schema
17+
18+
### Required
19+
20+
- `name` (String) The group name in groups/{email} format.
21+
22+
### Read-Only
23+
24+
- `create_time` (String) The group create time in YYYY-MM-DDThh:mm:ss.000Z format
25+
- `creator` (String) The group creator in users/{email} format.
26+
- `description` (String) The group description.
27+
- `id` (String) The ID of this resource.
28+
- `members` (Set of Object) The members in the group. (see [below for nested schema](#nestedatt--members))
29+
- `source` (String) Source means where the group comes from. For now we support Entra ID SCIM sync, so the source could be Entra ID.
30+
- `title` (String) The group title.
31+
32+
<a id="nestedatt--members"></a>
33+
### Nested Schema for `members`
34+
35+
Read-Only:
36+
37+
- `member` (String)
38+
- `role` (String)
39+
40+

docs/data-sources/group_list.md

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "bytebase_group_list Data Source - terraform-provider-bytebase"
4+
subcategory: ""
5+
description: |-
6+
The group data source list.
7+
---
8+
9+
# bytebase_group_list (Data Source)
10+
11+
The group data source list.
12+
13+
14+
15+
<!-- schema generated by tfplugindocs -->
16+
## Schema
17+
18+
### Read-Only
19+
20+
- `groups` (List of Object) (see [below for nested schema](#nestedatt--groups))
21+
- `id` (String) The ID of this resource.
22+
23+
<a id="nestedatt--groups"></a>
24+
### Nested Schema for `groups`
25+
26+
Read-Only:
27+
28+
- `create_time` (String)
29+
- `creator` (String)
30+
- `description` (String)
31+
- `members` (Set of Object) (see [below for nested schema](#nestedobjatt--groups--members))
32+
- `name` (String)
33+
- `source` (String)
34+
- `title` (String)
35+
36+
<a id="nestedobjatt--groups--members"></a>
37+
### Nested Schema for `groups.members`
38+
39+
Read-Only:
40+
41+
- `member` (String)
42+
- `role` (String)
43+
44+

docs/data-sources/instance.md

+3
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@ The instance data source.
2323

2424
- `data_sources` (List of Object) (see [below for nested schema](#nestedatt--data_sources))
2525
- `engine` (String) The instance engine. Support MYSQL, POSTGRES, TIDB, SNOWFLAKE, CLICKHOUSE, MONGODB, SQLITE, REDIS, ORACLE, SPANNER, MSSQL, REDSHIFT, MARIADB, OCEANBASE.
26+
- `engine_version` (String) The engine version.
2627
- `environment` (String) The environment name for your instance in "environments/{resource id}" format.
2728
- `external_link` (String) The external console URL managing this instance (e.g. AWS RDS console, your in-house DB instance console)
2829
- `id` (String) The ID of this resource.
30+
- `maximum_connections` (Number) The maximum number of connections. The default value is 10.
2931
- `name` (String) The instance full name in instances/{resource id} format.
32+
- `sync_interval` (Number) How often the instance is synced in seconds. Default 0, means never sync.
3033
- `title` (String) The instance title.
3134

3235
<a id="nestedatt--data_sources"></a>

docs/data-sources/instance_list.md

+3
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,13 @@ Read-Only:
3131

3232
- `data_sources` (List of Object) (see [below for nested schema](#nestedobjatt--instances--data_sources))
3333
- `engine` (String)
34+
- `engine_version` (String)
3435
- `environment` (String)
3536
- `external_link` (String)
37+
- `maximum_connections` (Number)
3638
- `name` (String)
3739
- `resource_id` (String)
40+
- `sync_interval` (Number)
3841
- `title` (String)
3942

4043
<a id="nestedobjatt--instances--data_sources"></a>

docs/data-sources/user.md

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ The user data source.
2727
- `last_login_time` (String) The user last login time.
2828
- `mfa_enabled` (Boolean) The mfa_enabled flag means if the user has enabled MFA.
2929
- `phone` (String) The user phone.
30+
- `roles` (Set of String) The user's roles in the workspace level
3031
- `source` (String) Source means where the user comes from. For now we support Entra ID SCIM sync, so the source could be Entra ID.
3132
- `state` (String) The user is deleted or not.
3233
- `title` (String) The user title.

docs/data-sources/user_list.md

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Read-Only:
3535
- `mfa_enabled` (Boolean)
3636
- `name` (String)
3737
- `phone` (String)
38+
- `roles` (Set of String)
3839
- `source` (String)
3940
- `state` (String)
4041
- `title` (String)

docs/resources/group.md

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "bytebase_group Resource - terraform-provider-bytebase"
4+
subcategory: ""
5+
description: |-
6+
The group resource.
7+
---
8+
9+
# bytebase_group (Resource)
10+
11+
The group resource.
12+
13+
14+
15+
<!-- schema generated by tfplugindocs -->
16+
## Schema
17+
18+
### Required
19+
20+
- `email` (String) The group email.
21+
- `members` (Block Set, Min: 1) The members in the group. (see [below for nested schema](#nestedblock--members))
22+
- `title` (String) The group title.
23+
24+
### Optional
25+
26+
- `description` (String) The group description.
27+
28+
### Read-Only
29+
30+
- `create_time` (String) The group create time in YYYY-MM-DDThh:mm:ss.000Z format
31+
- `creator` (String) The group creator in users/{email} format.
32+
- `id` (String) The ID of this resource.
33+
- `name` (String) The group name in groups/{email} format.
34+
- `source` (String) Source means where the group comes from. For now we support Entra ID SCIM sync, so the source could be Entra ID.
35+
36+
<a id="nestedblock--members"></a>
37+
### Nested Schema for `members`
38+
39+
Required:
40+
41+
- `member` (String) The member in users/{email} format.
42+
- `role` (String) The member's role in the group.
43+
44+

0 commit comments

Comments
 (0)