sudoo-cli 3.0.0__tar.gz → 3.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {sudoo_cli-3.0.0 → sudoo_cli-3.0.1}/PKG-INFO +6 -1
- {sudoo_cli-3.0.0 → sudoo_cli-3.0.1}/README.md +5 -0
- {sudoo_cli-3.0.0 → sudoo_cli-3.0.1}/pyproject.toml +1 -1
- {sudoo_cli-3.0.0 → sudoo_cli-3.0.1}/pyproject.toml.orig +1 -1
- {sudoo_cli-3.0.0 → sudoo_cli-3.0.1}/src/sudoo_cli/__init__.py +1 -1
- {sudoo_cli-3.0.0 → sudoo_cli-3.0.1}/src/sudoo_cli/cli.py +48 -0
- {sudoo_cli-3.0.0 → sudoo_cli-3.0.1}/src/sudoo_cli/commands.py +188 -0
- {sudoo_cli-3.0.0 → sudoo_cli-3.0.1}/LICENSE.md +0 -0
- {sudoo_cli-3.0.0 → sudoo_cli-3.0.1}/src/sudoo_cli/__main__.py +0 -0
- {sudoo_cli-3.0.0 → sudoo_cli-3.0.1}/src/sudoo_cli/client.py +0 -0
- {sudoo_cli-3.0.0 → sudoo_cli-3.0.1}/src/sudoo_cli/completion.py +0 -0
- {sudoo_cli-3.0.0 → sudoo_cli-3.0.1}/src/sudoo_cli/config.py +0 -0
- {sudoo_cli-3.0.0 → sudoo_cli-3.0.1}/src/sudoo_cli/context.py +0 -0
- {sudoo_cli-3.0.0 → sudoo_cli-3.0.1}/src/sudoo_cli/errors.py +0 -0
- {sudoo_cli-3.0.0 → sudoo_cli-3.0.1}/src/sudoo_cli/jobs.py +0 -0
- {sudoo_cli-3.0.0 → sudoo_cli-3.0.1}/src/sudoo_cli/output.py +0 -0
- {sudoo_cli-3.0.0 → sudoo_cli-3.0.1}/src/sudoo_cli/signing.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sudoo-cli
|
|
3
|
-
Version: 3.0.
|
|
3
|
+
Version: 3.0.1
|
|
4
4
|
Summary: The sudoo command: manage the projects, instances, backups, domains and jobs of a Sudoo.sh panel from a terminal or a CI pipeline.
|
|
5
5
|
Keywords: sudoo,odoo,cli,devops,ci
|
|
6
6
|
Author: Sudoo.sh
|
|
@@ -30,6 +30,8 @@ Description-Content-Type: text/markdown
|
|
|
30
30
|
|
|
31
31
|
# sudoo-cli
|
|
32
32
|
|
|
33
|
+
[](https://pypi.org/project/sudoo-cli/)
|
|
34
|
+
|
|
33
35
|
`sudoo` is the command-line client of the [Sudoo.sh](https://sudoo.sh) panel: list and create instances, deploy
|
|
34
36
|
the latest code of a branch, follow jobs live, back up and restore, manage custom domains and read caught mail, from
|
|
35
37
|
a terminal or a CI pipeline. Every request is signed with your API token's signing secret, exactly as the panel's
|
|
@@ -39,8 +41,11 @@ It needs Python 3.12 or later and nothing else (the OS keyring is optional).
|
|
|
39
41
|
|
|
40
42
|
## Install
|
|
41
43
|
|
|
44
|
+
`sudoo-cli` is published on [PyPI](https://pypi.org/project/sudoo-cli/).
|
|
45
|
+
|
|
42
46
|
```bash
|
|
43
47
|
pipx install sudoo-cli # or: uv tool install sudoo-cli
|
|
48
|
+
pip install sudoo-cli # in a virtual environment
|
|
44
49
|
pipx install 'sudoo-cli[keyring]' # keep credentials in the OS keyring
|
|
45
50
|
```
|
|
46
51
|
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# sudoo-cli
|
|
2
2
|
|
|
3
|
+
[](https://pypi.org/project/sudoo-cli/)
|
|
4
|
+
|
|
3
5
|
`sudoo` is the command-line client of the [Sudoo.sh](https://sudoo.sh) panel: list and create instances, deploy
|
|
4
6
|
the latest code of a branch, follow jobs live, back up and restore, manage custom domains and read caught mail, from
|
|
5
7
|
a terminal or a CI pipeline. Every request is signed with your API token's signing secret, exactly as the panel's
|
|
@@ -9,8 +11,11 @@ It needs Python 3.12 or later and nothing else (the OS keyring is optional).
|
|
|
9
11
|
|
|
10
12
|
## Install
|
|
11
13
|
|
|
14
|
+
`sudoo-cli` is published on [PyPI](https://pypi.org/project/sudoo-cli/).
|
|
15
|
+
|
|
12
16
|
```bash
|
|
13
17
|
pipx install sudoo-cli # or: uv tool install sudoo-cli
|
|
18
|
+
pip install sudoo-cli # in a virtual environment
|
|
14
19
|
pipx install 'sudoo-cli[keyring]' # keep credentials in the OS keyring
|
|
15
20
|
```
|
|
16
21
|
|
|
@@ -16,6 +16,12 @@ STAGES = ("development", "staging", "production")
|
|
|
16
16
|
EDITIONS = ("community", "enterprise")
|
|
17
17
|
STATUSES = ("creating", "online", "starting", "busy", "paused", "switched_off", "stopped", "unknown")
|
|
18
18
|
|
|
19
|
+
TEAMS_HELP = (
|
|
20
|
+
"teams of accounts and their access to projects and branches. Teams are a premium feature (Pro and Business): "
|
|
21
|
+
"on other plans the panel answers 403 when you create a team, add members or give access; reading, taking "
|
|
22
|
+
"members out, taking access away and deleting always work"
|
|
23
|
+
)
|
|
24
|
+
|
|
19
25
|
EPILOG = """\
|
|
20
26
|
Credentials come from `sudoo login` (a profile) or from SUDOO_URL, SUDOO_TOKEN and SUDOO_SECRET.
|
|
21
27
|
Exit codes: 0 ok, 1 error, 2 usage, 3 not logged in or credentials refused, 4 not allowed, 5 not found,
|
|
@@ -78,6 +84,11 @@ class Builder:
|
|
|
78
84
|
p = self.top.add_parser(name, help=help_, description=help_)
|
|
79
85
|
return p.add_subparsers(dest="subcommand", metavar="ACTION", required=True)
|
|
80
86
|
|
|
87
|
+
def subgroup(self, parent: Any, name: str, help_: str) -> Any:
|
|
88
|
+
"""A group inside a group (`sudoo teams members add ...`)."""
|
|
89
|
+
p = parent.add_parser(name, help=help_, description=help_)
|
|
90
|
+
return p.add_subparsers(dest="action", metavar="ACTION", required=True)
|
|
91
|
+
|
|
81
92
|
def cmd(self, parent: Any, name: str, help_: str, handler: Handler, job: bool = False) -> argparse.ArgumentParser:
|
|
82
93
|
p: argparse.ArgumentParser = parent.add_parser(name, help=help_, description=help_, parents=[self.common])
|
|
83
94
|
p.set_defaults(handler=handler)
|
|
@@ -295,6 +306,43 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
295
306
|
b.cmd(g, "list", "every account (needs a write token)", commands.users_list)
|
|
296
307
|
b.cmd(g, "roles", "the roles and their permissions", commands.roles_list)
|
|
297
308
|
|
|
309
|
+
# teams (premium)
|
|
310
|
+
g = b.group("teams", TEAMS_HELP)
|
|
311
|
+
b.cmd(g, "list", "every team, with its members and the projects that name it", commands.teams_list)
|
|
312
|
+
p = b.cmd(g, "show", "a team: its members and projects", commands.teams_show)
|
|
313
|
+
p.add_argument("team", help="the team's id or name")
|
|
314
|
+
p = b.cmd(g, "create", "make a team", commands.teams_create)
|
|
315
|
+
p.add_argument("name")
|
|
316
|
+
p.add_argument("--description")
|
|
317
|
+
p.add_argument("--member", action="append", metavar="ACCOUNT", help="an account to add (repeat for more)")
|
|
318
|
+
p = b.cmd(g, "rename", "give a team a new name (and description)", commands.teams_rename)
|
|
319
|
+
p.add_argument("team", help="the team's id or name")
|
|
320
|
+
p.add_argument("name", help="the new name")
|
|
321
|
+
p.add_argument("--description")
|
|
322
|
+
p = b.cmd(g, "delete", "delete a team; it leaves every grant and lock", commands.teams_delete)
|
|
323
|
+
p.add_argument("team", help="the team's id or name")
|
|
324
|
+
p.add_argument("--yes", "-y", action="store_true", help="do not ask")
|
|
325
|
+
members = b.subgroup(g, "members", "add accounts to a team or take them out")
|
|
326
|
+
for name, handler, help_ in (
|
|
327
|
+
("add", commands.teams_members_add, "add accounts to a team"),
|
|
328
|
+
("remove", commands.teams_members_remove, "take accounts out of a team"),
|
|
329
|
+
):
|
|
330
|
+
p = b.cmd(members, name, help_, handler)
|
|
331
|
+
p.add_argument("team", help="the team's id or name")
|
|
332
|
+
p.add_argument("accounts", nargs="+", metavar="ACCOUNT", help="the panel account's name")
|
|
333
|
+
grants = b.subgroup(g, "grants", "the levels teams have in projects and branches")
|
|
334
|
+
p = b.cmd(grants, "list", "a project's grants (teams and accounts) and its branches'", commands.teams_grants_list)
|
|
335
|
+
p.add_argument("project", help="the project's id")
|
|
336
|
+
p = b.cmd(grants, "set", "give a team a level in a project or one of its branches", commands.teams_grants_set)
|
|
337
|
+
p.add_argument("team", help="the team's id or name")
|
|
338
|
+
p.add_argument("project", help="the project's id")
|
|
339
|
+
p.add_argument("level", choices=commands.ACCESS_LEVELS)
|
|
340
|
+
p.add_argument("--branch", help="only this branch")
|
|
341
|
+
p = b.cmd(grants, "remove", "take a team's grant in a project or branch away", commands.teams_grants_remove)
|
|
342
|
+
p.add_argument("team", help="the team's id or name")
|
|
343
|
+
p.add_argument("project", help="the project's id")
|
|
344
|
+
p.add_argument("--branch", help="only this branch")
|
|
345
|
+
|
|
298
346
|
p = b.cmd(top, "completion", "print a shell completion script", lambda ctx: completion.run(ctx, b.root))
|
|
299
347
|
p.add_argument("shell", choices=("bash", "zsh", "fish"))
|
|
300
348
|
return b.root
|
|
@@ -914,3 +914,191 @@ def roles_list(ctx: Context) -> None:
|
|
|
914
914
|
response.data.get("roles") or [],
|
|
915
915
|
[("role", get("name")), ("label", get("label")), ("description", get("description"))],
|
|
916
916
|
)
|
|
917
|
+
|
|
918
|
+
|
|
919
|
+
# -- teams (premium: Pro and Business) --------------------------------------------------------------------------------
|
|
920
|
+
|
|
921
|
+
ACCESS_LEVELS = ("none", "view", "developer", "maintainer", "admin")
|
|
922
|
+
|
|
923
|
+
|
|
924
|
+
def _team(ctx: Context, ref: str) -> dict[str, Any]:
|
|
925
|
+
"""A team by its id or its name (case aside)."""
|
|
926
|
+
teams: list[dict[str, Any]] = ctx.client.get("/teams").data or []
|
|
927
|
+
for team in teams:
|
|
928
|
+
if team.get("id") == ref:
|
|
929
|
+
return team
|
|
930
|
+
wanted = ref.casefold()
|
|
931
|
+
for team in teams:
|
|
932
|
+
if str(team.get("name", "")).casefold() == wanted:
|
|
933
|
+
return team
|
|
934
|
+
raise CliError(f"There is no team {ref}.", NOT_FOUND)
|
|
935
|
+
|
|
936
|
+
|
|
937
|
+
def _member_names(team: dict[str, Any]) -> list[str]:
|
|
938
|
+
return [str(m.get("name")) if isinstance(m, dict) else str(m) for m in team.get("members") or []]
|
|
939
|
+
|
|
940
|
+
|
|
941
|
+
def _show_team(ctx: Context, team: dict[str, Any]) -> None:
|
|
942
|
+
if ctx.json:
|
|
943
|
+
emit_json(team)
|
|
944
|
+
return
|
|
945
|
+
fields(
|
|
946
|
+
[
|
|
947
|
+
("Team", f"{team.get('name')} ({team.get('id')})"),
|
|
948
|
+
("Description", team.get("description") or "-"),
|
|
949
|
+
("Projects", ", ".join(str(p.get("name") or p.get("id")) for p in team.get("projects") or []) or "-"),
|
|
950
|
+
("Created", f"{when(team.get('created_at'))} by {team.get('created_by') or '-'}"),
|
|
951
|
+
("Changed", f"{when(team.get('changed_at'))} by {team.get('changed_by') or '-'}"),
|
|
952
|
+
]
|
|
953
|
+
)
|
|
954
|
+
print()
|
|
955
|
+
table(
|
|
956
|
+
[m for m in team.get("members") or [] if isinstance(m, dict)],
|
|
957
|
+
[("member", get("name")), ("name", get("display_name")), ("role", get("role"))],
|
|
958
|
+
"No members.",
|
|
959
|
+
)
|
|
960
|
+
|
|
961
|
+
|
|
962
|
+
def teams_list(ctx: Context) -> None:
|
|
963
|
+
response = ctx.client.get("/teams")
|
|
964
|
+
if ctx.json:
|
|
965
|
+
emit_json(response.json())
|
|
966
|
+
return
|
|
967
|
+
table(
|
|
968
|
+
response.data or [],
|
|
969
|
+
[
|
|
970
|
+
("id", get("id")),
|
|
971
|
+
("team", get("name")),
|
|
972
|
+
("members", lambda t: len(t.get("members") or [])),
|
|
973
|
+
("projects", lambda t: ", ".join(str(p.get("id")) for p in t.get("projects") or []) or "-"),
|
|
974
|
+
("description", lambda t: (t.get("description") or "-")[:50]),
|
|
975
|
+
],
|
|
976
|
+
"No teams.",
|
|
977
|
+
)
|
|
978
|
+
|
|
979
|
+
|
|
980
|
+
def teams_show(ctx: Context) -> None:
|
|
981
|
+
_show_team(ctx, _team(ctx, ctx.args.team))
|
|
982
|
+
|
|
983
|
+
|
|
984
|
+
def teams_create(ctx: Context) -> None:
|
|
985
|
+
a = ctx.args
|
|
986
|
+
body: dict[str, Any] = {"name": a.name}
|
|
987
|
+
if a.description is not None:
|
|
988
|
+
body["description"] = a.description
|
|
989
|
+
if a.member:
|
|
990
|
+
body["members"] = sorted(set(a.member))
|
|
991
|
+
_show_team(ctx, ctx.client.post("/teams", body).data)
|
|
992
|
+
|
|
993
|
+
|
|
994
|
+
def _change_team(ctx: Context, team: dict[str, Any], body: dict[str, Any]) -> None:
|
|
995
|
+
_show_team(ctx, ctx.client.request("PATCH", f"/teams/{quote(str(team['id']))}", body).data)
|
|
996
|
+
|
|
997
|
+
|
|
998
|
+
def teams_rename(ctx: Context) -> None:
|
|
999
|
+
a = ctx.args
|
|
1000
|
+
body: dict[str, Any] = {"name": a.name}
|
|
1001
|
+
if a.description is not None:
|
|
1002
|
+
body["description"] = a.description
|
|
1003
|
+
_change_team(ctx, _team(ctx, a.team), body)
|
|
1004
|
+
|
|
1005
|
+
|
|
1006
|
+
def teams_delete(ctx: Context) -> None:
|
|
1007
|
+
team = _team(ctx, ctx.args.team)
|
|
1008
|
+
ctx.confirm(f"Delete the team {team.get('name')} (it leaves every project grant and branch lock)?")
|
|
1009
|
+
ctx.client.request("DELETE", f"/teams/{quote(str(team['id']))}")
|
|
1010
|
+
if ctx.json:
|
|
1011
|
+
emit_json({"deleted": team.get("id")})
|
|
1012
|
+
else:
|
|
1013
|
+
print(f"Team {team.get('name')} deleted.")
|
|
1014
|
+
|
|
1015
|
+
|
|
1016
|
+
def teams_members_add(ctx: Context) -> None:
|
|
1017
|
+
team = _team(ctx, ctx.args.team)
|
|
1018
|
+
members = sorted(set(_member_names(team)) | set(ctx.args.accounts))
|
|
1019
|
+
_change_team(ctx, team, {"members": members})
|
|
1020
|
+
|
|
1021
|
+
|
|
1022
|
+
def teams_members_remove(ctx: Context) -> None:
|
|
1023
|
+
team = _team(ctx, ctx.args.team)
|
|
1024
|
+
current = _member_names(team)
|
|
1025
|
+
missing = sorted(set(ctx.args.accounts) - set(current))
|
|
1026
|
+
if missing:
|
|
1027
|
+
raise CliError(
|
|
1028
|
+
f"{', '.join(missing)} {'is' if len(missing) == 1 else 'are'} not in {team.get('name')}.", NOT_FOUND
|
|
1029
|
+
)
|
|
1030
|
+
_change_team(ctx, team, {"members": sorted(set(current) - set(ctx.args.accounts))})
|
|
1031
|
+
|
|
1032
|
+
|
|
1033
|
+
def _access_body(access: dict[str, Any]) -> dict[str, Any]:
|
|
1034
|
+
"""The project's access as PUT /projects/<id>/access takes it (without the names the panel adds)."""
|
|
1035
|
+
|
|
1036
|
+
def plain(grants: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
|
1037
|
+
return [{"type": g.get("type"), "id": g.get("id"), "level": g.get("level")} for g in grants or []]
|
|
1038
|
+
|
|
1039
|
+
return {
|
|
1040
|
+
"mode": access.get("mode"),
|
|
1041
|
+
"grants": plain(access.get("grants") or []),
|
|
1042
|
+
"branches": {
|
|
1043
|
+
name: {"restricted": bool(b.get("restricted")), "grants": plain(b.get("grants") or [])}
|
|
1044
|
+
for name, b in (access.get("branches") or {}).items()
|
|
1045
|
+
},
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
|
|
1049
|
+
def _show_access(ctx: Context, project: str, access: dict[str, Any]) -> None:
|
|
1050
|
+
if ctx.json:
|
|
1051
|
+
emit_json(access)
|
|
1052
|
+
return
|
|
1053
|
+
rows = [{"where": "project", **g} for g in access.get("grants") or []]
|
|
1054
|
+
for name, branch in sorted((access.get("branches") or {}).items()):
|
|
1055
|
+
restricted = " (restricted)" if branch.get("restricted") else ""
|
|
1056
|
+
rows += [{"where": f"branch {name}{restricted}", **g} for g in branch.get("grants") or []]
|
|
1057
|
+
print(f"Project {project}: {access.get('mode')}")
|
|
1058
|
+
table(
|
|
1059
|
+
rows,
|
|
1060
|
+
[
|
|
1061
|
+
("where", get("where")),
|
|
1062
|
+
("type", get("type")),
|
|
1063
|
+
("id", get("id")),
|
|
1064
|
+
("name", get("name")),
|
|
1065
|
+
("level", get("level")),
|
|
1066
|
+
],
|
|
1067
|
+
"No grants: the panel roles decide.",
|
|
1068
|
+
)
|
|
1069
|
+
|
|
1070
|
+
|
|
1071
|
+
def teams_grants_list(ctx: Context) -> None:
|
|
1072
|
+
project = ctx.args.project
|
|
1073
|
+
_show_access(ctx, project, ctx.client.get(f"/projects/{quote(project)}/access").data)
|
|
1074
|
+
|
|
1075
|
+
|
|
1076
|
+
def _change_grant(ctx: Context, level: str | None) -> None:
|
|
1077
|
+
"""Give the team a level in the project or one of its branches (level None: take its grant away)."""
|
|
1078
|
+
a = ctx.args
|
|
1079
|
+
team = _team(ctx, a.team)
|
|
1080
|
+
path = f"/projects/{quote(a.project)}/access"
|
|
1081
|
+
body = _access_body(ctx.client.get(path).data)
|
|
1082
|
+
if a.branch:
|
|
1083
|
+
branch = body["branches"].setdefault(a.branch, {"restricted": False, "grants": []})
|
|
1084
|
+
grants = branch["grants"]
|
|
1085
|
+
else:
|
|
1086
|
+
grants = body["grants"]
|
|
1087
|
+
others = [g for g in grants if not (g.get("type") == "team" and g.get("id") == team["id"])]
|
|
1088
|
+
if level is None and len(others) == len(grants):
|
|
1089
|
+
where = f"branch {a.branch} of {a.project}" if a.branch else a.project
|
|
1090
|
+
raise CliError(f"The team {team.get('name')} has no grant in {where}.", NOT_FOUND)
|
|
1091
|
+
if level is not None:
|
|
1092
|
+
others.append({"type": "team", "id": team["id"], "level": level})
|
|
1093
|
+
grants[:] = others
|
|
1094
|
+
if a.branch and not grants and not body["branches"][a.branch]["restricted"]:
|
|
1095
|
+
del body["branches"][a.branch]
|
|
1096
|
+
_show_access(ctx, a.project, ctx.client.request("PUT", path, body).data)
|
|
1097
|
+
|
|
1098
|
+
|
|
1099
|
+
def teams_grants_set(ctx: Context) -> None:
|
|
1100
|
+
_change_grant(ctx, ctx.args.level)
|
|
1101
|
+
|
|
1102
|
+
|
|
1103
|
+
def teams_grants_remove(ctx: Context) -> None:
|
|
1104
|
+
_change_grant(ctx, None)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|