Skip to content

Commit

Permalink
[okta] add more None type checks (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrooTheChen authored Apr 23, 2024
1 parent ab0a97a commit 663f5ef
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions api/services/okta_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,24 +134,48 @@ def update_group(self, groupId: str, name: str, description: str) -> Group:
return Group(group)

async def async_add_user_to_group(self, groupId: str, userId: str) -> None:
if groupId is None or groupId == "":
logger.warning(f"cannot add user to groupId of {groupId}")
return
if userId is None or userId == "":
logger.warning(f"cannot add user to userId of {userId}")
return
_, error = await OktaService._retry(self.okta_client.add_user_to_group, groupId, userId)
if error is not None:
raise Exception(error)
return

def add_user_to_group(self, groupId: str, userId: str) -> None:
if groupId is None or groupId == "":
logger.warning(f"cannot add user to groupId of {groupId}")
return
if userId is None or userId == "":
logger.warning(f"cannot add user to userId of {userId}")
return
_, error = asyncio.run(OktaService._retry(self.okta_client.add_user_to_group, groupId, userId))
if error is not None:
raise Exception(error)
return

async def async_remove_user_from_group(self, groupId: str, userId: str) -> None:
if groupId is None or groupId == "":
logger.warning(f"cannot remove user from groupId of {groupId}")
return
if userId is None or userId == "":
logger.warning(f"cannot remove user from userId of {userId}")
return
_, error = await OktaService._retry(self.okta_client.remove_user_from_group, groupId, userId)
if error is not None:
raise Exception(error)
return

def remove_user_from_group(self, groupId: str, userId: str) -> None:
if groupId is None or groupId == "":
logger.warning(f"cannot remove user from groupId of {groupId}")
return
if userId is None or userId == "":
logger.warning(f"cannot remove user from userId of {userId}")
return
_, error = asyncio.run(OktaService._retry(self.okta_client.remove_user_from_group, groupId, userId))

if error is not None:
Expand Down Expand Up @@ -245,6 +269,12 @@ def delete_group(self, groupId: str) -> None:

# https://developer.okta.com/docs/api/openapi/okta-management/management/tag/Group/#tag/Group/operation/assignGroupOwner
def add_owner_to_group(self, groupId: str, userId: str) -> None:
if groupId is None or groupId == "":
logger.warning(f"cannot add owner to groupId of {groupId}")
return
if userId is None or userId == "":
logger.warning(f"cannot add owner to userId of {userId}")
return
asyncio.run(self.async_add_owner_to_group(groupId, userId))

async def async_add_owner_to_group(self, groupId: str, userId: str) -> None:
Expand Down Expand Up @@ -276,6 +306,12 @@ async def async_add_owner_to_group(self, groupId: str, userId: str) -> None:

# https://developer.okta.com/docs/api/openapi/okta-management/management/tag/Group/#tag/Group/operation/deleteGroupOwner
def remove_owner_from_group(self, groupId: str, userId: str) -> None:
if groupId is None or groupId == "":
logger.warning(f"cannot to remove owner from groupId of {groupId}")
return
if userId is None or userId == "":
logger.warning(f"cannot remove owner from userId of {userId}")
return
asyncio.run(self.async_remove_owner_from_group(groupId, userId))

async def async_remove_owner_from_group(self, groupId: str, userId: str) -> None:
Expand Down Expand Up @@ -306,6 +342,9 @@ async def async_remove_owner_from_group(self, groupId: str, userId: str) -> None

# https://developer.okta.com/docs/api/openapi/okta-management/management/tag/Group/#tag/Group/operation/listGroupOwners
def list_owners_for_group(self, groupId: str) -> list[User]:
if groupId is None or groupId == "":
logger.warning(f"cannot to list owners for groupId of {groupId}")
return []
if not self.use_group_owners_api:
return []

Expand Down

0 comments on commit 663f5ef

Please sign in to comment.