|
1 | | -# Copyright 2024 Rapyuta Robotics |
| 1 | +# Copyright 2025 Rapyuta Robotics |
2 | 2 | # |
3 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
4 | 4 | # you may not use this file except in compliance with the License. |
|
11 | 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | | -import typing |
15 | | - |
16 | 14 | import click |
17 | 15 | from click_help_colors import HelpColorsCommand |
18 | | -from rapyuta_io.clients import UserGroup |
19 | 16 |
|
20 | | -from riocli.config import new_client |
| 17 | +from riocli.config import get_config_from_context |
21 | 18 | from riocli.constants import Colors |
22 | | -from riocli.usergroup.util import name_to_guid |
23 | 19 | from riocli.utils import inspect_with_format |
24 | 20 |
|
25 | 21 |
|
|
38 | 34 | ) |
39 | 35 | @click.argument("group-name") |
40 | 36 | @click.pass_context |
41 | | -@name_to_guid |
42 | 37 | 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, |
44 | 41 | ) -> None: |
45 | 42 | """Print the details of a usergroup |
46 | 43 |
|
47 | 44 | You choose the format of the output using the ``--format`` flag. |
48 | 45 | The supported formats are ``json`` and ``yaml``. Default is ``yaml``. |
49 | 46 | """ |
50 | 47 | 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) |
55 | 52 | except Exception as e: |
56 | 53 | click.secho(str(e), fg=Colors.RED) |
57 | 54 | raise SystemExit(1) |
58 | 55 |
|
59 | 56 |
|
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 | | - } |
0 commit comments