Skip to content

Commit ab19903

Browse files
committed
feat(usergroup): support v2 Usergroup API and manifest
1 parent 5e7f26b commit ab19903

File tree

8 files changed

+232
-253
lines changed

8 files changed

+232
-253
lines changed

riocli/apply/manifests/usergroup.yaml

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,28 @@ metadata:
88
spec:
99
description: This is a sample user group description
1010
members:
11-
- emailID: [email protected]
12-
- emailID: [email protected]
13-
admins:
14-
- emailID: [email protected]
15-
projects:
16-
- name: project01
17-
role: viewer
18-
- name: project02
19-
role: admin
11+
- subject:
12+
kind: User
13+
14+
roles:
15+
- kind: Role
16+
name: group_viewer
17+
- subject:
18+
kind: ServiceAccount
19+
name: sa-paramsync
20+
roles:
21+
- kind: Role
22+
name: group_viewer
23+
roles:
24+
- domain:
25+
kind: Project
26+
name: site-1
27+
role:
28+
kind: Role
29+
name: project_admin
30+
- domain:
31+
kind: Project
32+
name: site-2
33+
role:
34+
kind: Role
35+
name: project_viewer

riocli/jsonschema/schemas/usergroup-schema.yaml

Lines changed: 66 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ definitions:
4545

4646
required:
4747
- name
48-
- organization
4948

5049
usergroupSpec:
5150
type: object
@@ -57,29 +56,84 @@ definitions:
5756
type: array
5857
items:
5958
"$ref": "#/definitions/member"
60-
admins:
59+
roles:
6160
type: array
6261
items:
63-
"$ref": "#/definitions/member"
64-
projects:
62+
"$ref": "#/definitions/groupRole"
63+
additionalProperties: false
64+
65+
groupRole:
66+
type: object
67+
properties:
68+
domain:
69+
$ref: "#/definitions/domain"
70+
roles:
6571
type: array
6672
items:
67-
"$ref": "#/definitions/project"
68-
additionalProperties: false
73+
$ref: "#/definitions/role"
74+
75+
domain:
76+
type: object
77+
properties:
78+
kind:
79+
type: string
80+
enum:
81+
- Organization
82+
- Project
83+
name:
84+
type: string
85+
guid:
86+
type: string
87+
oneOf:
88+
- required:
89+
- name
90+
- required:
91+
- guid
6992

7093
member:
7194
type: object
7295
properties:
96+
subject:
97+
$ref: "#/definitions/subject"
98+
roles:
99+
type: array
100+
items:
101+
$ref: "#/definitions/role"
102+
103+
subject:
104+
type: object
105+
properties:
106+
kind:
107+
type: string
108+
enum:
109+
- User
110+
- ServiceAccount
111+
name:
112+
type: string
73113
guid:
74-
$ref: "#/definitions/uuid"
75-
emailID:
76114
type: string
115+
oneOf:
116+
- required:
117+
- guid
118+
- required:
119+
- name
77120

121+
role:
122+
type: object
123+
properties:
124+
kind:
125+
type: string
126+
const: Role
127+
default: Role
128+
name:
129+
type: string
130+
guid:
131+
type: string
78132
oneOf:
79-
- required:
80-
- guid
81-
- required:
82-
- emailID
133+
- required:
134+
- name
135+
- required:
136+
- guid
83137

84138
project:
85139
type: object

riocli/usergroup/delete.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Rapyuta Robotics
1+
# Copyright 2025 Rapyuta Robotics
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
1616
from click_help_colors import HelpColorsCommand
1717
from yaspin.api import Yaspin
1818

19-
from riocli.config import new_client
19+
from riocli.config import get_config_from_context
2020
from riocli.constants import Colors, Symbols
2121
from riocli.usergroup.util import name_to_guid
2222
from riocli.utils.spinner import with_spinner
@@ -60,9 +60,9 @@ def delete_usergroup(
6060
)
6161

6262
try:
63-
client = new_client()
64-
org_guid = ctx.obj.data.get("organization_id")
65-
client.delete_usergroup(org_guid, group_guid)
63+
config = get_config_from_context(ctx)
64+
client = config.new_v2_client(with_project=False)
65+
client.delete_usergroup(group_guid=group_guid, group_name=group_name)
6666
spinner.text = click.style("User group deleted successfully.", fg=Colors.GREEN)
6767
spinner.green.ok(Symbols.SUCCESS)
6868
except Exception as e:

riocli/usergroup/inspect.py

Lines changed: 9 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Rapyuta Robotics
1+
# Copyright 2025 Rapyuta Robotics
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -11,15 +11,11 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
import typing
15-
1614
import click
1715
from click_help_colors import HelpColorsCommand
18-
from rapyuta_io.clients import UserGroup
1916

20-
from riocli.config import new_client
17+
from riocli.config import get_config_from_context
2118
from riocli.constants import Colors
22-
from riocli.usergroup.util import name_to_guid
2319
from riocli.utils import inspect_with_format
2420

2521

@@ -38,52 +34,23 @@
3834
)
3935
@click.argument("group-name")
4036
@click.pass_context
41-
@name_to_guid
4237
def inspect_usergroup(
43-
ctx: click.Context, format_type: str, group_name: str, group_guid: str, spinner=None
38+
ctx: click.Context,
39+
format_type: str,
40+
group_name: str,
4441
) -> None:
4542
"""Print the details of a usergroup
4643
4744
You choose the format of the output using the ``--format`` flag.
4845
The supported formats are ``json`` and ``yaml``. Default is ``yaml``.
4946
"""
5047
try:
51-
client = new_client()
52-
org_guid = ctx.obj.data.get("organization_id")
53-
usergroup = client.get_usergroup(org_guid, group_guid)
54-
inspect_with_format(to_manifest(usergroup, org_guid), format_type)
48+
config = get_config_from_context(ctx)
49+
client = config.new_v2_client(with_project=False)
50+
usergroup = client.list_usergroups(query={"name": group_name})
51+
inspect_with_format(usergroup, format_type)
5552
except Exception as e:
5653
click.secho(str(e), fg=Colors.RED)
5754
raise SystemExit(1)
5855

5956

60-
def to_manifest(usergroup: UserGroup, org_guid: str) -> typing.Dict:
61-
"""
62-
Transform a usergroup resource to a rio apply manifest construct
63-
"""
64-
role_map = {
65-
i["projectGUID"]: i["groupRole"] for i in (usergroup.role_in_projects or [])
66-
}
67-
members = {m.email_id for m in usergroup.members}
68-
admins = {a.email_id for a in usergroup.admins}
69-
projects = [
70-
{"name": p.name, "role": role_map.get(p.guid)}
71-
for p in (usergroup.projects or [])
72-
if p.guid in role_map
73-
]
74-
75-
return {
76-
"apiVersion": "api.rapyuta.io/v2",
77-
"kind": "UserGroup",
78-
"metadata": {
79-
"name": usergroup.name,
80-
"creator": usergroup.creator,
81-
"organization": org_guid,
82-
},
83-
"spec": {
84-
"description": usergroup.description,
85-
"members": [{"emailID": m} for m in list(members - admins)],
86-
"admins": [{"emailID": a} for a in list(admins)],
87-
"projects": projects,
88-
},
89-
}

riocli/usergroup/list.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Rapyuta Robotics
1+
# Copyright 2025 Rapyuta Robotics
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -17,7 +17,7 @@
1717
import click
1818
from click_help_colors import HelpColorsCommand
1919

20-
from riocli.config import new_client
20+
from riocli.config import new_v2_client
2121
from riocli.constants import Colors
2222
from riocli.utils import tabulate_data
2323

@@ -32,9 +32,8 @@
3232
def list_usergroup(ctx: click.Context) -> None:
3333
"""List all user groups in current organization."""
3434
try:
35-
client = new_client()
36-
org_guid = ctx.obj.data.get("organization_id")
37-
user_groups = client.list_usergroups(org_guid)
35+
client = new_v2_client(with_project=False)
36+
user_groups = client.list_usergroups()
3837
_display_usergroup_list(user_groups)
3938
except Exception as e:
4039
click.secho(str(e), fg=Colors.RED)
@@ -46,16 +45,15 @@ def _display_usergroup_list(usergroups: typing.Any, show_header: bool = True):
4645
if show_header:
4746
headers = ("ID", "Name", "Creator", "Members", "Projects", "Description")
4847

49-
data = [
50-
[
51-
group.guid,
52-
group.name,
53-
group.creator,
54-
len(group.members) if group.members else 0,
55-
len(group.projects) if group.projects else 0,
56-
group.description,
57-
]
58-
for group in usergroups
59-
]
60-
61-
tabulate_data(data, headers)
48+
rows = []
49+
for g in usergroups:
50+
rows.append(
51+
[
52+
g.metadata.guid,
53+
g.metadata.name,
54+
g.metadata.creatorGUID,
55+
g.spec.membersCount,
56+
g.spec.description,
57+
]
58+
)
59+
tabulate_data(rows, headers)

0 commit comments

Comments
 (0)