Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 100 additions & 1 deletion src/conductor/asyncio_client/adapters/api/application_resource_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,103 @@
from typing import List

from pydantic import StrictStr

from conductor.asyncio_client.http.api import ApplicationResourceApi
from conductor.asyncio_client.http.models import Tag


class ApplicationResourceApiAdapter(ApplicationResourceApi):
async def create_access_key(
self,
id: StrictStr,
*args,
**kwargs,
):
# Convert empty application id to None to prevent sending invalid data to server
if not id:
id = None
return await super().create_access_key(id=id, *args, **kwargs)

async def add_role_to_application_user(
self, application_id: StrictStr, role: StrictStr, *args, **kwargs
):
# Convert empty application_id and role to None to prevent sending invalid data to server
if not application_id:
application_id = None
if not role:
role = None
return await super().add_role_to_application_user(
application_id=application_id, role=role, *args, **kwargs
)

async def delete_access_key(
self,
application_id: StrictStr,
key_id: StrictStr,
*args,
**kwargs,
):
# Convert empty application_id and key_id to None to prevent sending invalid data to server
if not application_id:
application_id = None
if not key_id:
key_id = None
return await super().delete_access_key(
application_id=application_id, key_id=key_id, *args, **kwargs
)

async def remove_role_from_application_user(
self,
application_id: StrictStr,
role: StrictStr,
*args,
**kwargs,
):
# Convert empty application_id and role to None to prevent sending invalid data to server
if not application_id:
application_id = None
if not role:
role = None
return await super().remove_role_from_application_user(
application_id=application_id, role=role, *args, **kwargs
)

async def get_app_by_access_key_id(self, access_key_id: StrictStr, *args, **kwargs):
# Convert empty access_key_id to None to prevent sending invalid data to server
if not access_key_id:
access_key_id = None
return await super().get_app_by_access_key_id(access_key_id=access_key_id, *args, **kwargs)

async def get_access_keys(self, id: StrictStr, *args, **kwargs):
# Convert empty application id to None to prevent sending invalid data to server
if not id:
id = None
return await super().get_access_keys(id=id, *args, **kwargs)

async def toggle_access_key_status(
self, application_id: StrictStr, key_id: StrictStr, *args, **kwargs
):
# Convert empty application_id and key_id to None to prevent sending invalid data to server
if not application_id:
application_id = None
if not key_id:
key_id = None
return await super().toggle_access_key_status(
application_id=application_id, key_id=key_id, *args, **kwargs
)

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

class ApplicationResourceApiAdapter(ApplicationResourceApi): ...
async def delete_tag_for_application(
self, id: StrictStr, tag: List[Tag], *args, **kwargs
) -> None:
# Convert empty application id and tag list to None to prevent sending invalid data to server
if not id:
id = None
if not tag:
tag = None
return await super().delete_tag_for_application(id=id, tag=tag, *args, **kwargs)
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ def field_name_validate_enum(cls, value):
"oAuth2AuthCode",
"oAuth2TokenExpiresAt",
"oAuth2RedirectUri",
"oAuth2Scope",
"oAuth2Provider",
"oAuth2AccessToken",
]
):
raise ValueError(
Expand Down
107 changes: 36 additions & 71 deletions src/conductor/asyncio_client/orkes/orkes_authorization_client.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import annotations

from typing import Dict, List, Optional
from typing import List

from conductor.asyncio_client.adapters import ApiClient
from conductor.asyncio_client.adapters.models.authorization_request_adapter import (
AuthorizationRequestAdapter as AuthorizationRequest,
)
Expand All @@ -11,31 +12,23 @@
from conductor.asyncio_client.adapters.models.extended_conductor_application_adapter import (
ExtendedConductorApplicationAdapter as ExtendedConductorApplication,
)
from conductor.asyncio_client.adapters.models.tag_adapter import TagAdapter as Tag
from conductor.asyncio_client.adapters.models.granted_access_adapter import (
GrantedAccessAdapter as GrantedAccess,
)
from conductor.asyncio_client.adapters.models.group_adapter import GroupAdapter as Group
from conductor.asyncio_client.adapters.models.tag_adapter import TagAdapter as Tag
from conductor.asyncio_client.adapters.models.target_ref_adapter import (
TargetRefAdapter as TargetRef,
)
from conductor.asyncio_client.adapters.models.upsert_group_request_adapter import (
UpsertGroupRequestAdapter as UpsertGroupRequest,
)
from conductor.asyncio_client.adapters.models.upsert_user_request_adapter import (
UpsertUserRequestAdapter as UpsertUserRequest,
)
from conductor.asyncio_client.adapters import ApiClient
from conductor.asyncio_client.configuration.configuration import Configuration
from conductor.asyncio_client.orkes.orkes_base_client import OrkesBaseClient
from conductor.asyncio_client.adapters.models.create_or_update_application_request_adapter import (
CreateOrUpdateApplicationRequestAdapter,
)
from conductor.client.orkes.models.access_key import AccessKey
from conductor.client.orkes.models.access_type import AccessType
from conductor.asyncio_client.adapters.models.subject_ref_adapter import (
SubjectRefAdapter as SubjectRef,
)
from conductor.asyncio_client.adapters.models.target_ref_adapter import (
TargetRefAdapter as TargetRef,
)
from conductor.asyncio_client.adapters.models.granted_access_adapter import (
GrantedAccessAdapter as GrantedAccess,
)


class OrkesAuthorizationClient(OrkesBaseClient):
Expand All @@ -47,17 +40,13 @@ async def create_user(
self, user_id: str, upsert_user_request: UpsertUserRequest
) -> ConductorUser:
"""Create a new user"""
return await self.user_api.upsert_user(
id=user_id, upsert_user_request=upsert_user_request
)
return await self.user_api.upsert_user(id=user_id, upsert_user_request=upsert_user_request)

async def update_user(
self, user_id: str, upsert_user_request: UpsertUserRequest
) -> ConductorUser:
"""Update an existing user"""
return await self.user_api.upsert_user(
id=user_id, upsert_user_request=upsert_user_request
)
return await self.user_api.upsert_user(id=user_id, upsert_user_request=upsert_user_request)

async def get_user(self, user_id: str) -> ConductorUser:
"""Get user by ID"""
Expand Down Expand Up @@ -93,9 +82,7 @@ async def update_application(
)
return ExtendedConductorApplication.from_dict(app)

async def get_application(
self, application_id: str
) -> ExtendedConductorApplication:
async def get_application(self, application_id: str) -> ExtendedConductorApplication:
"""Get application by ID"""
app = await self.application_api.get_application(id=application_id)
return ExtendedConductorApplication.from_dict(app)
Expand All @@ -109,17 +96,13 @@ async def list_applications(self) -> List[ExtendedConductorApplication]:
return await self.application_api.list_applications()

# Group Operations
async def create_group(
self, group_id: str, upsert_group_request: UpsertGroupRequest
) -> Group:
async def create_group(self, group_id: str, upsert_group_request: UpsertGroupRequest) -> Group:
"""Create a new group"""
return await self.group_api.upsert_group(
id=group_id, upsert_group_request=upsert_group_request
)

async def update_group(
self, group_id: str, upsert_group_request: UpsertGroupRequest
) -> Group:
async def update_group(self, group_id: str, upsert_group_request: UpsertGroupRequest) -> Group:
"""Update an existing group"""
group = await self.group_api.upsert_group(
id=group_id, upsert_group_request=upsert_group_request
Expand All @@ -142,25 +125,17 @@ async def list_groups(self) -> List[Group]:
# Group User Management Operations
async def add_user_to_group(self, group_id: str, user_id: str) -> object:
"""Add a user to a group"""
return await self.group_api.add_user_to_group(
group_id=group_id, user_id=user_id
)
return await self.group_api.add_user_to_group(group_id=group_id, user_id=user_id)

async def remove_user_from_group(self, group_id: str, user_id: str) -> object:
"""Remove a user from a group"""
return await self.group_api.remove_user_from_group(
group_id=group_id, user_id=user_id
)
return await self.group_api.remove_user_from_group(group_id=group_id, user_id=user_id)

async def add_users_to_group(self, group_id: str, user_ids: List[str]) -> object:
"""Add multiple users to a group"""
return await self.group_api.add_users_to_group(
group_id=group_id, request_body=user_ids
)
return await self.group_api.add_users_to_group(group_id=group_id, request_body=user_ids)

async def remove_users_from_group(
self, group_id: str, user_ids: List[str]
) -> object:
async def remove_users_from_group(self, group_id: str, user_ids: List[str]) -> object:
"""Remove multiple users from a group"""
return await self.group_api.remove_users_from_group(
group_id=group_id, request_body=user_ids
Expand All @@ -171,27 +146,21 @@ async def get_users_in_group(self, group_id: str) -> object:
return await self.group_api.get_users_in_group(id=group_id)

# Permission Operations (Only available operations)
async def grant_permissions(
self, authorization_request: AuthorizationRequest
) -> object:
async def grant_permissions(self, authorization_request: AuthorizationRequest) -> object:
"""Grant permissions to users or groups"""
return await self.authorization_api.grant_permissions(
authorization_request=authorization_request
)

async def remove_permissions(
self, authorization_request: AuthorizationRequest
) -> object:
async def remove_permissions(self, authorization_request: AuthorizationRequest) -> object:
"""Remove permissions from users or groups"""
return await self.authorization_api.remove_permissions(
authorization_request=authorization_request
)

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

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

async def upsert_group(
self, group_id: str, upsert_group_request: UpsertGroupRequest
) -> Group:
async def upsert_group(self, group_id: str, upsert_group_request: UpsertGroupRequest) -> Group:
"""Alias for create_group/update_group"""
group = await self.create_group(group_id, upsert_group_request)
return Group.from_dict(group)
Expand All @@ -219,7 +186,7 @@ async def get_application_tags(self, application_id: str) -> List[Tag]:
return await self.application_api.get_tags_for_application(application_id)

async def delete_application_tags(self, tags: List[Tag], application_id: str):
await self.application_api.delete_tag_for_application(tags, application_id)
await self.application_api.delete_tag_for_application(application_id, tags)

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

return access_keys

async def toggle_access_key_status(
self, application_id: str, key_id: str
) -> AccessKey:
key_obj = await self.application_api.toggle_access_key_status(
application_id, key_id
)
async def toggle_access_key_status(self, application_id: str, key_id: str) -> AccessKey:
key_obj = await self.application_api.toggle_access_key_status(application_id, key_id)
return key_obj

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

async def remove_role_from_application_user(self, application_id: str, role: str):
await self.application_api.remove_role_from_application_user(
application_id, role
)
await self.application_api.remove_role_from_application_user(application_id, role)

async def get_granted_permissions_for_group(
self, group_id: str
) -> List[GrantedAccess]:
async def get_granted_permissions_for_group(self, group_id: str) -> List[GrantedAccess]:
granted_access_obj = await self.group_api.get_granted_permissions1(group_id)
granted_permissions = []
for ga in granted_access_obj.granted_access:
Expand All @@ -263,13 +222,19 @@ async def get_granted_permissions_for_group(
granted_permissions.append(GrantedAccess(target=target, access=access))
return granted_permissions

async def get_granted_permissions_for_user(
self, user_id: str
) -> List[GrantedAccess]:
async def get_granted_permissions_for_user(self, user_id: str) -> List[GrantedAccess]:
granted_access_obj = await self.user_api.get_granted_permissions(user_id)
granted_permissions = []
for ga in granted_access_obj["grantedAccess"]:
target = TargetRef(type=ga["target"]["type"], id=ga["target"]["id"])
access = ga["access"]
granted_permissions.append(GrantedAccess(target=target, access=access))
return granted_permissions

async def get_app_by_access_key_id(
self, access_key_id: str, *args, **kwargs
) -> ExtendedConductorApplication:
application_access_key_obj = await self.application_api.get_app_by_access_key_id(
access_key_id=access_key_id, *args, **kwargs
)
return ExtendedConductorApplication.from_dict(application_access_key_obj)
Loading