Skip to content

Commit 37ee1da

Browse files
chore: update more deprecated api calls (#267)
1 parent 4189c55 commit 37ee1da

File tree

4 files changed

+53
-25
lines changed

4 files changed

+53
-25
lines changed

qnexus/client/quotas.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import Literal
44

55
from qnexus.client import get_nexus_client
6+
from qnexus.client.users import get_self
67
from qnexus.exceptions import ResourceFetchFailed
78
from qnexus.models import Quota
89
from qnexus.models.references import DataframableList
@@ -21,8 +22,15 @@
2122

2223
def get_all() -> DataframableList[Quota]:
2324
"""Get all quotas, including usage."""
25+
user = get_self()
26+
2427
res = get_nexus_client().get(
25-
"/api/quotas/v1beta", params={"entity_type": "user", "include_usage": True}
28+
"/api/quotas/v1beta",
29+
params={
30+
"entity_type": "user",
31+
"entity_id": str(user.id),
32+
"include_usage": True,
33+
},
2634
)
2735

2836
if res.status_code != 200:
@@ -50,9 +58,16 @@ def get_all() -> DataframableList[Quota]:
5058

5159
def get(name: QuotaName) -> Quota:
5260
"""Get specific quota details by name."""
61+
user = get_self()
62+
5363
res = get_nexus_client().get(
54-
"/api/quotas/v1beta",
55-
params={"entity_type": "user", "name": name, "include_usage": True},
64+
"/api/quotas/v1beta3",
65+
params={
66+
"entity_type": "user",
67+
"entity_id": str(user.id),
68+
"name": name,
69+
"include_usage": True,
70+
}, # needs user id
5671
)
5772

5873
if res.status_code != 200:
@@ -73,7 +88,10 @@ def get(name: QuotaName) -> Quota:
7388

7489
def check_quota(name: QuotaName) -> bool:
7590
"""Check that the current user has available quota."""
76-
res = get_nexus_client().get("/api/quotas/v1beta/guard", params={"name": name})
91+
user = get_self()
92+
res = get_nexus_client().get(
93+
"/api/quotas/v1beta3/guard", params={"name": name, "user_id": str(user.id)}
94+
)
7795

7896
if res.status_code != 200:
7997
return False

qnexus/client/roles.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def assignments(resource_ref: BaseRef) -> DataframableList[RoleInfo]:
5252
"""Check the assignments on a particular resource."""
5353

5454
res = get_nexus_client().get(
55-
f"/api/resources/v1beta/{resource_ref.id}/assignments",
55+
f"/api/resources/v1beta2/{resource_ref.id}/assignments",
5656
)
5757

5858
if res.status_code != 200:

qnexus/client/teams.py

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
def get_all() -> DataframableList[TeamRef]:
99
"""No fuzzy name matching."""
1010
res = get_nexus_client().get(
11-
"/api/v5/user/teams",
11+
"/api/teams/v1beta2",
1212
)
1313

1414
if res.status_code != 200:
@@ -18,10 +18,10 @@ def get_all() -> DataframableList[TeamRef]:
1818
[
1919
TeamRef(
2020
id=team["id"],
21-
name=team["team_name"],
22-
description=team["description"],
21+
name=team["attributes"]["name"],
22+
description=team["attributes"]["description"],
2323
)
24-
for team in res.json()
24+
for team in res.json()["data"]
2525
]
2626
)
2727

@@ -31,9 +31,11 @@ def get(name: str) -> TeamRef:
3131
Get a single team using filters. Throws an exception if the filters do not
3232
match exactly one object.
3333
"""
34-
res = get_nexus_client().get("/api/v5/user/teams", params={"name": name})
34+
res = get_nexus_client().get(
35+
"/api/teams/v1beta2", params={"filter[team][name]": name}
36+
)
3537

36-
if res.status_code == 404 or res.json() == []:
38+
if res.status_code == 404 or res.json()["data"] == []:
3739
raise qnx_exc.ZeroMatches
3840

3941
if res.status_code != 200:
@@ -42,13 +44,14 @@ def get(name: str) -> TeamRef:
4244
teams_list = [
4345
TeamRef(
4446
id=team["id"],
45-
name=team["team_name"],
46-
description=team["description"],
47+
name=team["attributes"]["name"],
48+
description=team["attributes"]["description"],
4749
)
48-
for team in res.json()
50+
for team in res.json()["data"]
4951
]
5052

5153
if len(teams_list) > 1:
54+
print(teams_list)
5255
raise qnx_exc.NoUniqueMatch
5356

5457
return teams_list[0]
@@ -58,31 +61,38 @@ def _fetch_by_id(team_id: str) -> TeamRef:
5861
"""
5962
Get a single team by id.
6063
"""
61-
res = get_nexus_client().get(f"/api/v5/user/teams/{team_id}")
64+
res = get_nexus_client().get(f"/api/teams/v1beta2/{team_id}")
6265

6366
if res.status_code == 404:
6467
raise qnx_exc.ZeroMatches
6568

6669
if res.status_code != 200:
6770
raise qnx_exc.ResourceFetchFailed(message=res.text, status_code=res.status_code)
6871

69-
team_dict = res.json()
72+
team_dict = res.json()["data"]
7073

7174
return TeamRef(
7275
id=team_dict["id"],
73-
name=team_dict["team_name"],
74-
description=team_dict["description"],
76+
name=team_dict["attributes"]["name"],
77+
description=team_dict["attributes"]["description"],
7578
)
7679

7780

7881
def create(name: str, description: str | None = None) -> TeamRef:
7982
"""Create a team in Nexus."""
8083

8184
resp = get_nexus_client().post(
82-
"api/v5/user/teams/new",
85+
"/api/teams/v1beta2",
8386
json={
84-
"team_name": name,
85-
"description": description,
87+
"data": {
88+
"attributes": {
89+
"name": name,
90+
"description": description,
91+
"display_name": name,
92+
},
93+
"relationships": {},
94+
"type": "team",
95+
},
8696
},
8797
)
8898

@@ -91,9 +101,9 @@ def create(name: str, description: str | None = None) -> TeamRef:
91101
message=resp.text, status_code=resp.status_code
92102
)
93103

94-
team_dict = resp.json()
104+
team_dict = resp.json()["data"]
95105
return TeamRef(
96106
id=team_dict["id"],
97-
name=team_dict["team_name"],
98-
description=team_dict["description"],
107+
name=team_dict["attributes"]["name"],
108+
description=team_dict["attributes"]["description"],
99109
)

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)