Skip to content

Commit

Permalink
Ensure backward comptability for User Management
Browse files Browse the repository at this point in the history
  • Loading branch information
coderabhigupta committed Nov 3, 2023
1 parent d032bde commit c6d1bfe
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 20 deletions.
8 changes: 4 additions & 4 deletions src/conductor/client/http/api/user_resource_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def get_user(self, id, **kwargs): # noqa: E501
:param async_req bool
:param str id: (required)
:return: ConductorUser
:return: object
If the method is called asynchronously,
returns the request thread.
"""
Expand Down Expand Up @@ -291,7 +291,7 @@ def get_user_with_http_info(self, id, **kwargs): # noqa: E501
body=body_params,
post_params=form_params,
files=local_var_files,
response_type='ConductorUser', # noqa: E501
response_type='object', # noqa: E501
auth_settings=auth_settings,
async_req=params.get('async_req'),
_return_http_data_only=params.get('_return_http_data_only'),
Expand Down Expand Up @@ -399,7 +399,7 @@ def upsert_user(self, body, id, **kwargs): # noqa: E501
:param async_req bool
:param UpsertUserRequest body: (required)
:param str id: (required)
:return: ConductorUser
:return: object
If the method is called asynchronously,
returns the request thread.
"""
Expand Down Expand Up @@ -485,7 +485,7 @@ def upsert_user_with_http_info(self, body, id, **kwargs): # noqa: E501
body=body_params,
post_params=form_params,
files=local_var_files,
response_type='ConductorUser', # noqa: E501
response_type='object', # noqa: E501
auth_settings=auth_settings,
async_req=params.get('async_req'),
_return_http_data_only=params.get('_return_http_data_only'),
Expand Down
3 changes: 3 additions & 0 deletions src/conductor/client/http/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ def deserialize(self, response, response_type):
f'failed to deserialize data {data} into class {response_type}, reason: {e}')
return None

def deserialize_class(self, data, klass):
return self.__deserialize(data, klass)

def __deserialize(self, data, klass):
"""Deserializes dict, list, str into an object.
Expand Down
56 changes: 53 additions & 3 deletions src/conductor/client/http/models/conductor_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ class ConductorUser(object):
'roles': 'list[Role]',
'groups': 'list[Group]',
'uuid': 'str',
'application_user': 'bool'
'application_user': 'bool',
'encrypted_id': 'bool',
'encrypted_id_display_value': 'str'
}

attribute_map = {
Expand All @@ -30,10 +32,12 @@ class ConductorUser(object):
'roles': 'roles',
'groups': 'groups',
'uuid': 'uuid',
'application_user': 'applicationUser'
'application_user': 'applicationUser',
'encrypted_id': 'encryptedId',
'encrypted_id_display_value': 'encryptedIdDisplayValue'
}

def __init__(self, id=None, name=None, roles=None, groups=None, uuid=None, application_user=None): # noqa: E501
def __init__(self, id=None, name=None, roles=None, groups=None, uuid=None, application_user=None, encrypted_id=None, encrypted_id_display_value=None): # noqa: E501
"""ConductorUser - a model defined in Swagger""" # noqa: E501
self._id = None
self._name = None
Expand All @@ -54,6 +58,10 @@ def __init__(self, id=None, name=None, roles=None, groups=None, uuid=None, appli
self.uuid = uuid
if application_user is not None:
self.application_user = application_user
if encrypted_id is not None:
self.encrypted_id = encrypted_id
if encrypted_id_display_value is not None:
self.encrypted_id_display_value = encrypted_id_display_value

@property
def id(self):
Expand Down Expand Up @@ -181,6 +189,48 @@ def application_user(self, application_user):

self._application_user = application_user

@property
def encrypted_id(self):
"""Gets the encrypted_id of this ConductorUser. # noqa: E501
:return: The encrypted_id of this ConductorUser. # noqa: E501
:rtype: bool
"""
return self._encrypted_id

@encrypted_id.setter
def encrypted_id(self, encrypted_id):
"""Sets the encrypted_id of this ConductorUser.
:param encrypted_id: The encrypted_id of this ConductorUser. # noqa: E501
:type: bool
"""

self._encrypted_id = encrypted_id

@property
def encrypted_id_display_value(self):
"""Gets the encrypted_id_display_value of this ConductorUser. # noqa: E501
:return: The encrypted_id_display_value of this ConductorUser. # noqa: E501
:rtype: str
"""
return self._encrypted_id_display_value

@encrypted_id_display_value.setter
def encrypted_id_display_value(self, encrypted_id_display_value):
"""Sets the encrypted_id_display_value of this ConductorUser.
:param encrypted_id_display_value: The encrypted_id_display_value of this ConductorUser. # noqa: E501
:type: str
"""

self._encrypted_id_display_value = encrypted_id_display_value

def to_dict(self):
"""Returns the model properties as a dict"""
result = {}
Expand Down
16 changes: 9 additions & 7 deletions src/conductor/client/orkes/orkes_authorization_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@

class OrkesAuthorizationClient(AuthorizationClient):
def __init__(self, configuration: Configuration):
api_client = ApiClient(configuration)
self.applicationResourceApi = ApplicationResourceApi(api_client)
self.userResourceApi = UserResourceApi(api_client)
self.groupResourceApi = GroupResourceApi(api_client)
self.authorizationResourceApi = AuthorizationResourceApi(api_client)
self.api_client = ApiClient(configuration)
self.applicationResourceApi = ApplicationResourceApi(self.api_client)
self.userResourceApi = UserResourceApi(self.api_client)
self.groupResourceApi = GroupResourceApi(self.api_client)
self.authorizationResourceApi = AuthorizationResourceApi(self.api_client)

# Applications
def createApplication(
Expand Down Expand Up @@ -83,10 +83,12 @@ def deleteApplicationTags(self, tags: List[MetadataTag], applicationId: str):
# Users

def upsertUser(self, upsertUserRequest: UpsertUserRequest, userId: str) -> ConductorUser:
return self.userResourceApi.upsert_user(upsertUserRequest, userId)
user_obj = self.userResourceApi.upsert_user(upsertUserRequest, userId)
return self.api_client.deserialize_class(user_obj, "ConductorUser")

def getUser(self, userId: str) -> ConductorUser:
return self.userResourceApi.get_user(userId)
user_obj = self.userResourceApi.get_user(userId)
return self.api_client.deserialize_class(user_obj, "ConductorUser")

def listUsers(self, apps: Optional[bool] = False) -> List[ConductorUser]:
kwargs = { "apps": apps }
Expand Down
37 changes: 31 additions & 6 deletions tests/unit/orkes/test_authorization_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
from conductor.client.http.models.upsert_user_request import UpsertUserRequest
from conductor.client.http.models.upsert_group_request import UpsertGroupRequest
from conductor.client.http.models.authorization_request import AuthorizationRequest
from conductor.client.http.models.role import Role
from conductor.client.http.models.group import Group
from conductor.client.http.models.permission import Permission
from conductor.client.http.models.subject_ref import SubjectRef, SubjectType
from conductor.client.http.models.target_ref import TargetRef, TargetType
from conductor.client.http.models.conductor_user import ConductorUser
Expand All @@ -24,10 +26,10 @@
APP_ID = 'c6e75472'
APP_NAME = 'ut_application_name'
USER_ID = '[email protected]'
USER_UUID = 'ac8b5803-c391-4237-8d3d-90f74b07d5ad'
USER_NAME = 'UT USER'
GROUP_ID = 'ut_group'
GROUP_NAME = 'Test Group'
USER_NAME = 'UT USER'
ERROR_BODY= '{"message":"No such application found by id"}'

class TestOrkesAuthorizationClient(unittest.TestCase):
Expand All @@ -37,7 +39,24 @@ def setUpClass(cls):
configuration = Configuration("http://localhost:8080/api")
cls.authorization_client = OrkesAuthorizationClient(configuration)
cls.conductor_application = ConductorApplication(APP_ID, APP_NAME)
cls.conductor_user = ConductorUser(USER_NAME, ["ADMIN"])
cls.roles = [
Role(
"USER", [
Permission(name="METADATA_MANAGEMENT"),
Permission(name="WORKFLOW_MANAGEMENT"),
Permission(name="METADATA_VIEW")
]
)
]
cls.conductor_user = ConductorUser(
id=USER_ID,
name=USER_NAME,
uuid=USER_UUID,
roles=cls.roles,
application_user=False,
encrypted_id=False,
encrypted_id_display_value=USER_ID
)
cls.conductor_group= Group(GROUP_ID, GROUP_NAME, ["USER"])

def setUp(self):
Expand Down Expand Up @@ -129,17 +148,23 @@ def test_deleteApplicationTags(self, mock):
@patch.object(UserResourceApi, 'upsert_user')
def test_upsertUser(self, mock):
upsertReq = UpsertUserRequest(USER_NAME, ["ADMIN"])
mock.return_value = self.conductor_user
mock.return_value = self.conductor_user.to_dict()
user = self.authorization_client.upsertUser(upsertReq, USER_ID)
self.assertEqual(user, self.conductor_user)
mock.assert_called_with(upsertReq, USER_ID)
self.assertEqual(user.name, USER_NAME)
self.assertEqual(user.id, USER_ID)
self.assertEqual(user.uuid, USER_UUID)
self.assertEqual(user.roles, self.roles)

@patch.object(UserResourceApi, 'get_user')
def test_getUser(self, mock):
mock.return_value = self.conductor_user
mock.return_value = self.conductor_user.to_dict()
user = self.authorization_client.getUser(USER_ID)
mock.assert_called_with(USER_ID)
self.assertEqual(user, self.conductor_user)
self.assertEqual(user.name, USER_NAME)
self.assertEqual(user.id, USER_ID)
self.assertEqual(user.uuid, USER_UUID)
self.assertEqual(user.roles, self.roles)

@patch.object(UserResourceApi, 'list_users')
def test_listUsers_with_apps(self, mock):
Expand Down

0 comments on commit c6d1bfe

Please sign in to comment.