Skip to content

Commit cf33e65

Browse files
Fix application resource API inconsistencies (#347)
1 parent 4f29502 commit cf33e65

File tree

6 files changed

+473
-113
lines changed

6 files changed

+473
-113
lines changed
Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,103 @@
1+
from typing import List
2+
3+
from pydantic import StrictStr
4+
15
from conductor.asyncio_client.http.api import ApplicationResourceApi
6+
from conductor.asyncio_client.http.models import Tag
7+
8+
9+
class ApplicationResourceApiAdapter(ApplicationResourceApi):
10+
async def create_access_key(
11+
self,
12+
id: StrictStr,
13+
*args,
14+
**kwargs,
15+
):
16+
# Convert empty application id to None to prevent sending invalid data to server
17+
if not id:
18+
id = None
19+
return await super().create_access_key(id=id, *args, **kwargs)
20+
21+
async def add_role_to_application_user(
22+
self, application_id: StrictStr, role: StrictStr, *args, **kwargs
23+
):
24+
# Convert empty application_id and role to None to prevent sending invalid data to server
25+
if not application_id:
26+
application_id = None
27+
if not role:
28+
role = None
29+
return await super().add_role_to_application_user(
30+
application_id=application_id, role=role, *args, **kwargs
31+
)
32+
33+
async def delete_access_key(
34+
self,
35+
application_id: StrictStr,
36+
key_id: StrictStr,
37+
*args,
38+
**kwargs,
39+
):
40+
# Convert empty application_id and key_id to None to prevent sending invalid data to server
41+
if not application_id:
42+
application_id = None
43+
if not key_id:
44+
key_id = None
45+
return await super().delete_access_key(
46+
application_id=application_id, key_id=key_id, *args, **kwargs
47+
)
48+
49+
async def remove_role_from_application_user(
50+
self,
51+
application_id: StrictStr,
52+
role: StrictStr,
53+
*args,
54+
**kwargs,
55+
):
56+
# Convert empty application_id and role to None to prevent sending invalid data to server
57+
if not application_id:
58+
application_id = None
59+
if not role:
60+
role = None
61+
return await super().remove_role_from_application_user(
62+
application_id=application_id, role=role, *args, **kwargs
63+
)
64+
65+
async def get_app_by_access_key_id(self, access_key_id: StrictStr, *args, **kwargs):
66+
# Convert empty access_key_id to None to prevent sending invalid data to server
67+
if not access_key_id:
68+
access_key_id = None
69+
return await super().get_app_by_access_key_id(access_key_id=access_key_id, *args, **kwargs)
70+
71+
async def get_access_keys(self, id: StrictStr, *args, **kwargs):
72+
# Convert empty application id to None to prevent sending invalid data to server
73+
if not id:
74+
id = None
75+
return await super().get_access_keys(id=id, *args, **kwargs)
76+
77+
async def toggle_access_key_status(
78+
self, application_id: StrictStr, key_id: StrictStr, *args, **kwargs
79+
):
80+
# Convert empty application_id and key_id to None to prevent sending invalid data to server
81+
if not application_id:
82+
application_id = None
83+
if not key_id:
84+
key_id = None
85+
return await super().toggle_access_key_status(
86+
application_id=application_id, key_id=key_id, *args, **kwargs
87+
)
288

89+
async def get_tags_for_application(self, application_id: StrictStr, *args, **kwargs):
90+
# Convert empty application_id to None to prevent sending invalid data to server
91+
if not application_id:
92+
application_id = None
93+
return await super().get_tags_for_application(id=application_id, *args, **kwargs)
394

4-
class ApplicationResourceApiAdapter(ApplicationResourceApi): ...
95+
async def delete_tag_for_application(
96+
self, id: StrictStr, tag: List[Tag], *args, **kwargs
97+
) -> None:
98+
# Convert empty application id and tag list to None to prevent sending invalid data to server
99+
if not id:
100+
id = None
101+
if not tag:
102+
tag = None
103+
return await super().delete_tag_for_application(id=id, tag=tag, *args, **kwargs)

src/conductor/asyncio_client/orkes/orkes_authorization_client.py

Lines changed: 36 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from __future__ import annotations
22

3-
from typing import Dict, List, Optional
3+
from typing import List
44

5+
from conductor.asyncio_client.adapters import ApiClient
56
from conductor.asyncio_client.adapters.models.authorization_request_adapter import (
67
AuthorizationRequestAdapter as AuthorizationRequest,
78
)
@@ -11,31 +12,23 @@
1112
from conductor.asyncio_client.adapters.models.extended_conductor_application_adapter import (
1213
ExtendedConductorApplicationAdapter as ExtendedConductorApplication,
1314
)
14-
from conductor.asyncio_client.adapters.models.tag_adapter import TagAdapter as Tag
15+
from conductor.asyncio_client.adapters.models.granted_access_adapter import (
16+
GrantedAccessAdapter as GrantedAccess,
17+
)
1518
from conductor.asyncio_client.adapters.models.group_adapter import GroupAdapter as Group
19+
from conductor.asyncio_client.adapters.models.tag_adapter import TagAdapter as Tag
20+
from conductor.asyncio_client.adapters.models.target_ref_adapter import (
21+
TargetRefAdapter as TargetRef,
22+
)
1623
from conductor.asyncio_client.adapters.models.upsert_group_request_adapter import (
1724
UpsertGroupRequestAdapter as UpsertGroupRequest,
1825
)
1926
from conductor.asyncio_client.adapters.models.upsert_user_request_adapter import (
2027
UpsertUserRequestAdapter as UpsertUserRequest,
2128
)
22-
from conductor.asyncio_client.adapters import ApiClient
2329
from conductor.asyncio_client.configuration.configuration import Configuration
2430
from conductor.asyncio_client.orkes.orkes_base_client import OrkesBaseClient
25-
from conductor.asyncio_client.adapters.models.create_or_update_application_request_adapter import (
26-
CreateOrUpdateApplicationRequestAdapter,
27-
)
2831
from conductor.client.orkes.models.access_key import AccessKey
29-
from conductor.client.orkes.models.access_type import AccessType
30-
from conductor.asyncio_client.adapters.models.subject_ref_adapter import (
31-
SubjectRefAdapter as SubjectRef,
32-
)
33-
from conductor.asyncio_client.adapters.models.target_ref_adapter import (
34-
TargetRefAdapter as TargetRef,
35-
)
36-
from conductor.asyncio_client.adapters.models.granted_access_adapter import (
37-
GrantedAccessAdapter as GrantedAccess,
38-
)
3932

4033

4134
class OrkesAuthorizationClient(OrkesBaseClient):
@@ -47,17 +40,13 @@ async def create_user(
4740
self, user_id: str, upsert_user_request: UpsertUserRequest
4841
) -> ConductorUser:
4942
"""Create a new user"""
50-
return await self.user_api.upsert_user(
51-
id=user_id, upsert_user_request=upsert_user_request
52-
)
43+
return await self.user_api.upsert_user(id=user_id, upsert_user_request=upsert_user_request)
5344

5445
async def update_user(
5546
self, user_id: str, upsert_user_request: UpsertUserRequest
5647
) -> ConductorUser:
5748
"""Update an existing user"""
58-
return await self.user_api.upsert_user(
59-
id=user_id, upsert_user_request=upsert_user_request
60-
)
49+
return await self.user_api.upsert_user(id=user_id, upsert_user_request=upsert_user_request)
6150

6251
async def get_user(self, user_id: str) -> ConductorUser:
6352
"""Get user by ID"""
@@ -93,9 +82,7 @@ async def update_application(
9382
)
9483
return ExtendedConductorApplication.from_dict(app)
9584

96-
async def get_application(
97-
self, application_id: str
98-
) -> ExtendedConductorApplication:
85+
async def get_application(self, application_id: str) -> ExtendedConductorApplication:
9986
"""Get application by ID"""
10087
app = await self.application_api.get_application(id=application_id)
10188
return ExtendedConductorApplication.from_dict(app)
@@ -109,17 +96,13 @@ async def list_applications(self) -> List[ExtendedConductorApplication]:
10996
return await self.application_api.list_applications()
11097

11198
# Group Operations
112-
async def create_group(
113-
self, group_id: str, upsert_group_request: UpsertGroupRequest
114-
) -> Group:
99+
async def create_group(self, group_id: str, upsert_group_request: UpsertGroupRequest) -> Group:
115100
"""Create a new group"""
116101
return await self.group_api.upsert_group(
117102
id=group_id, upsert_group_request=upsert_group_request
118103
)
119104

120-
async def update_group(
121-
self, group_id: str, upsert_group_request: UpsertGroupRequest
122-
) -> Group:
105+
async def update_group(self, group_id: str, upsert_group_request: UpsertGroupRequest) -> Group:
123106
"""Update an existing group"""
124107
group = await self.group_api.upsert_group(
125108
id=group_id, upsert_group_request=upsert_group_request
@@ -142,25 +125,17 @@ async def list_groups(self) -> List[Group]:
142125
# Group User Management Operations
143126
async def add_user_to_group(self, group_id: str, user_id: str) -> object:
144127
"""Add a user to a group"""
145-
return await self.group_api.add_user_to_group(
146-
group_id=group_id, user_id=user_id
147-
)
128+
return await self.group_api.add_user_to_group(group_id=group_id, user_id=user_id)
148129

149130
async def remove_user_from_group(self, group_id: str, user_id: str) -> object:
150131
"""Remove a user from a group"""
151-
return await self.group_api.remove_user_from_group(
152-
group_id=group_id, user_id=user_id
153-
)
132+
return await self.group_api.remove_user_from_group(group_id=group_id, user_id=user_id)
154133

155134
async def add_users_to_group(self, group_id: str, user_ids: List[str]) -> object:
156135
"""Add multiple users to a group"""
157-
return await self.group_api.add_users_to_group(
158-
group_id=group_id, request_body=user_ids
159-
)
136+
return await self.group_api.add_users_to_group(group_id=group_id, request_body=user_ids)
160137

161-
async def remove_users_from_group(
162-
self, group_id: str, user_ids: List[str]
163-
) -> object:
138+
async def remove_users_from_group(self, group_id: str, user_ids: List[str]) -> object:
164139
"""Remove multiple users from a group"""
165140
return await self.group_api.remove_users_from_group(
166141
group_id=group_id, request_body=user_ids
@@ -171,27 +146,21 @@ async def get_users_in_group(self, group_id: str) -> object:
171146
return await self.group_api.get_users_in_group(id=group_id)
172147

173148
# Permission Operations (Only available operations)
174-
async def grant_permissions(
175-
self, authorization_request: AuthorizationRequest
176-
) -> object:
149+
async def grant_permissions(self, authorization_request: AuthorizationRequest) -> object:
177150
"""Grant permissions to users or groups"""
178151
return await self.authorization_api.grant_permissions(
179152
authorization_request=authorization_request
180153
)
181154

182-
async def remove_permissions(
183-
self, authorization_request: AuthorizationRequest
184-
) -> object:
155+
async def remove_permissions(self, authorization_request: AuthorizationRequest) -> object:
185156
"""Remove permissions from users or groups"""
186157
return await self.authorization_api.remove_permissions(
187158
authorization_request=authorization_request
188159
)
189160

190161
async def get_permissions(self, entity_type: str, entity_id: str) -> object:
191162
"""Get permissions for a specific entity (user, group, or application)"""
192-
return await self.authorization_api.get_permissions(
193-
type=entity_type, id=entity_id
194-
)
163+
return await self.authorization_api.get_permissions(type=entity_type, id=entity_id)
195164

196165
async def get_group_permissions(self, group_id: str) -> object:
197166
"""Get permissions granted to a group"""
@@ -205,9 +174,7 @@ async def upsert_user(
205174
user = await self.create_user(user_id, upsert_user_request)
206175
return ConductorUser.from_dict(user)
207176

208-
async def upsert_group(
209-
self, group_id: str, upsert_group_request: UpsertGroupRequest
210-
) -> Group:
177+
async def upsert_group(self, group_id: str, upsert_group_request: UpsertGroupRequest) -> Group:
211178
"""Alias for create_group/update_group"""
212179
group = await self.create_group(group_id, upsert_group_request)
213180
return Group.from_dict(group)
@@ -219,7 +186,7 @@ async def get_application_tags(self, application_id: str) -> List[Tag]:
219186
return await self.application_api.get_tags_for_application(application_id)
220187

221188
async def delete_application_tags(self, tags: List[Tag], application_id: str):
222-
await self.application_api.delete_tag_for_application(tags, application_id)
189+
await self.application_api.delete_tag_for_application(application_id, tags)
223190

224191
async def create_access_key(self, application_id: str) -> AccessKey:
225192
key_obj = await self.application_api.create_access_key(application_id)
@@ -233,12 +200,8 @@ async def get_access_keys(self, application_id: str) -> List[AccessKey]:
233200

234201
return access_keys
235202

236-
async def toggle_access_key_status(
237-
self, application_id: str, key_id: str
238-
) -> AccessKey:
239-
key_obj = await self.application_api.toggle_access_key_status(
240-
application_id, key_id
241-
)
203+
async def toggle_access_key_status(self, application_id: str, key_id: str) -> AccessKey:
204+
key_obj = await self.application_api.toggle_access_key_status(application_id, key_id)
242205
return key_obj
243206

244207
async def delete_access_key(self, application_id: str, key_id: str):
@@ -248,13 +211,9 @@ async def add_role_to_application_user(self, application_id: str, role: str):
248211
await self.application_api.add_role_to_application_user(application_id, role)
249212

250213
async def remove_role_from_application_user(self, application_id: str, role: str):
251-
await self.application_api.remove_role_from_application_user(
252-
application_id, role
253-
)
214+
await self.application_api.remove_role_from_application_user(application_id, role)
254215

255-
async def get_granted_permissions_for_group(
256-
self, group_id: str
257-
) -> List[GrantedAccess]:
216+
async def get_granted_permissions_for_group(self, group_id: str) -> List[GrantedAccess]:
258217
granted_access_obj = await self.group_api.get_granted_permissions1(group_id)
259218
granted_permissions = []
260219
for ga in granted_access_obj.granted_access:
@@ -263,13 +222,19 @@ async def get_granted_permissions_for_group(
263222
granted_permissions.append(GrantedAccess(target=target, access=access))
264223
return granted_permissions
265224

266-
async def get_granted_permissions_for_user(
267-
self, user_id: str
268-
) -> List[GrantedAccess]:
225+
async def get_granted_permissions_for_user(self, user_id: str) -> List[GrantedAccess]:
269226
granted_access_obj = await self.user_api.get_granted_permissions(user_id)
270227
granted_permissions = []
271228
for ga in granted_access_obj["grantedAccess"]:
272229
target = TargetRef(type=ga["target"]["type"], id=ga["target"]["id"])
273230
access = ga["access"]
274231
granted_permissions.append(GrantedAccess(target=target, access=access))
275232
return granted_permissions
233+
234+
async def get_app_by_access_key_id(
235+
self, access_key_id: str, *args, **kwargs
236+
) -> ExtendedConductorApplication:
237+
application_access_key_obj = await self.application_api.get_app_by_access_key_id(
238+
access_key_id=access_key_id, *args, **kwargs
239+
)
240+
return ExtendedConductorApplication.from_dict(application_access_key_obj)

0 commit comments

Comments
 (0)