Skip to content

Commit 5e636f5

Browse files
committed
chore: support group
1 parent 6d1758a commit 5e636f5

28 files changed

+982
-15
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.4
1+
1.0.5

api/client.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,18 @@ type Client interface {
128128
// UndeleteUser undeletes the user by name.
129129
UndeleteUser(ctx context.Context, userName string) (*v1pb.User, error)
130130

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+
131143
// Workspace
132144
// GetWorkspaceIAMPolicy gets the workspace IAM policy.
133145
GetWorkspaceIAMPolicy(ctx context.Context) (*v1pb.IamPolicy, error)

client/group.go

Lines changed: 92 additions & 0 deletions
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+
}

docs/data-sources/group.md

Lines changed: 40 additions & 0 deletions
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

Lines changed: 44 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 44 additions & 0 deletions
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)