From 7bb328d197b377b35ed0ea5c24ad2df4f7c3c4e6 Mon Sep 17 00:00:00 2001 From: velotioaastha Date: Thu, 25 Apr 2024 12:14:40 +0530 Subject: [PATCH] add functional documentation and inline comments --- wandb-scim/custom_roles.py | 90 +++++++++- wandb-scim/examples/custom_roles_example.py | 66 ++++++- wandb-scim/examples/teams_example.py | 47 ++++- wandb-scim/examples/user_example.py | 52 ++++++ wandb-scim/teams.py | 186 +++++++++++++------- wandb-scim/users.py | 79 ++++++++- 6 files changed, 448 insertions(+), 72 deletions(-) diff --git a/wandb-scim/custom_roles.py b/wandb-scim/custom_roles.py index 04ae5094..09b8389d 100644 --- a/wandb-scim/custom_roles.py +++ b/wandb-scim/custom_roles.py @@ -3,18 +3,41 @@ class CustomRole(object): def __init__(self, username, api_key): + """ + Initializes the CustomRole object with username and API key. + + Args: + username (str): The username for authentication. + api_key (str): The API key for authentication. + """ + # Encode the username and API key into a base64-encoded string for Basic Authentication auth_str = f"{username}:{api_key}" auth_bytes = auth_str.encode('ascii') self.auth_token = base64.b64encode(auth_bytes).decode('ascii') + + # Create the authorization header for API requests self.authorization_header = f"Basic {self.auth_token}" def _create_custom_role(self, url, request_payload): + """ + Creates a new custom role. + + Args: + url (str): The URL for the custom role creation endpoint. + request_payload (dict): The payload containing custom role data. + It should contain the following keys: + - 'permissionJson': The permissions JSON for the custom role. + - 'inheritedFrom': The inheritance information for the custom role. + + Returns: + str: A message indicating whether the custom role creation was successful or failed. + """ print("Creating the custom role") data = { "schemas": ["urn:ietf:params:scim:schemas:core:2.0:Role"], "name": "Sample custom role", "description": "A sample custom role for example", - "permissions": [request_payload['permissionjson']], + "permissions": [request_payload['permissionJson']], "inheritedFrom": request_payload['inheritedFrom'] } headers = { @@ -28,6 +51,15 @@ def _create_custom_role(self, url, request_payload): return f"Custom role creation failed. Status code: {response.status_code}" def _get_custom_role(self, url): + """ + Retrieves custom role details. + + Args: + url (str): The URL for the custom role retrieval endpoint. + + Returns: + str: A message containing custom role details or indicating failure. + """ print("Getting the custom role") headers = { @@ -42,6 +74,15 @@ def _get_custom_role(self, url): return f"Get custom role failed. Status code: {response.status_code}" def _get_all_custom_role(self, url): + """ + Retrieves details of all custom roles in the organization. + + Args: + url (str): The URL for the endpoint to get all custom roles. + + Returns: + str: A message containing details of all custom roles or indicating failure. + """ print("Getting all the custom roles in org") headers = { @@ -56,6 +97,18 @@ def _get_all_custom_role(self, url): return f"Get all custom roles failed. Status code: {response.status_code}" def _add_permission(self, url, request_payload): + """ + Adds permission to a custom role. + + Args: + url (str): The URL for the endpoint to add permission to the custom role. + request_payload (dict): The payload containing permission information. + It should contain the following key: + - 'permissionJson': The permissions JSON to be added to the custom role. + + Returns: + str: A message indicating whether the permission addition was successful or failed. + """ print("Add permission to a custom role") data = { "schemas": ["urn:ietf:params:scim:api:messages:2.0:PatchOp"], @@ -86,6 +139,18 @@ def _add_permission(self, url, request_payload): return f"Failed to update custom role. Status code: {response.status_code}" def _remove_permission(self, url, request_payload): + """ + Removes permission from a custom role. + + Args: + url (str): The URL for the endpoint to remove permission from the custom role. + request_payload (dict): The payload containing permission information. + It should contain the following key: + - 'permissionJson': The permissions JSON to be removed from the custom role. + + Returns: + str: A message indicating whether the permission removal was successful or failed. + """ print("Remove permission from a custom role") data = { "schemas": ["urn:ietf:params:scim:api:messages:2.0:PatchOp"], @@ -115,6 +180,20 @@ def _remove_permission(self, url, request_payload): return f"Failed to update custom role. Status code: {response.status_code}" def _update_custom_role(self, url, request_payload): + """ + Updates name and description of a custom role. + + Args: + url (str): The URL for the endpoint to update the custom role. + request_payload (dict): The payload containing role information. + It should contain the following keys: + - 'roleName': The name of the custom role. + - 'roleDescription': The description of the custom role. + - 'inheritedFrom': The inheritance information for the custom role. + + Returns: + str: A message indicating whether the custom role update was successful or failed. + """ print("Update name and description of custom role") data = { "schemas": ["urn:ietf:params:scim:schemas:core:2.0:Role"], @@ -140,6 +219,15 @@ def _update_custom_role(self, url, request_payload): return f"Failed to update custom role. Status code: {response.status_code}" def _delete_custom_role(self, url): + """ + Deletes a custom role. + + Args: + url (str): The URL for the endpoint to delete the custom role. + + Returns: + str: A message indicating whether the custom role deletion was successful or failed. + """ print("Deleting custom role") headers = { diff --git a/wandb-scim/examples/custom_roles_example.py b/wandb-scim/examples/custom_roles_example.py index 1eabebe3..ec783f1e 100644 --- a/wandb-scim/examples/custom_roles_example.py +++ b/wandb-scim/examples/custom_roles_example.py @@ -1,15 +1,26 @@ +# calling_module.py + import requests import sys sys.path.append('../') from custom_roles import CustomRole # Assuming CustomRole class is defined in custom_role.py def create_custom_role(base_url, custom_role, permission_json, inherited_from): + """ + Creates a new custom role. + + Args: + base_url (str): The base URL of the API. + custom_role (CustomRole): An instance of the CustomRole class. + permission_json (str): JSON string representing permissions for the custom role. + inherited_from (str): The source from which the custom role inherits permissions. + """ try: # Create a new custom role create_role_response = custom_role._create_custom_role( url=f"{base_url}/Roles", request_payload={ - "permissionjson": permission_json, + "permissionJson": permission_json, "inheritedFrom": inherited_from } ) @@ -18,6 +29,14 @@ def create_custom_role(base_url, custom_role, permission_json, inherited_from): print(f"Error occurred during API request: {str(e)}") def get_custom_role(base_url, custom_role, role_id): + """ + Retrieves details of a specific custom role. + + Args: + base_url (str): The base URL of the API. + custom_role (CustomRole): An instance of the CustomRole class. + role_id (str): The ID of the custom role to retrieve. + """ try: # Get details of a custom role get_role_response = custom_role._get_custom_role(f"{base_url}/Roles/{role_id}") @@ -26,6 +45,13 @@ def get_custom_role(base_url, custom_role, role_id): print(f"Error occurred during API request: {str(e)}") def get_all_roles(base_url, custom_role): + """ + Retrieves details of all custom roles. + + Args: + base_url (str): The base URL of the API. + custom_role (CustomRole): An instance of the CustomRole class. + """ try: # Get all custom roles get_all_roles_response = custom_role._get_all_custom_role(f"{base_url}/Roles") @@ -34,6 +60,15 @@ def get_all_roles(base_url, custom_role): print(f"Error occurred during API request: {str(e)}") def add_permission(base_url, custom_role, role_id, permission_json): + """ + Adds permission to a custom role. + + Args: + base_url (str): The base URL of the API. + custom_role (CustomRole): An instance of the CustomRole class. + role_id (str): The ID of the custom role to update. + permission_json (str): JSON string representing the permission to add. + """ try: # Add permission to a custom role update_role_response = custom_role._add_permission( @@ -47,6 +82,15 @@ def add_permission(base_url, custom_role, role_id, permission_json): print(f"Error occurred during API request: {str(e)}") def remove_permission(base_url, custom_role, role_id, permission_json): + """ + Removes permission from a custom role. + + Args: + base_url (str): The base URL of the API. + custom_role (CustomRole): An instance of the CustomRole class. + role_id (str): The ID of the custom role to update. + permission_json (str): JSON string representing the permission to remove. + """ try: # Remove permission from a custom role remove_role_response = custom_role._remove_permission( @@ -60,6 +104,17 @@ def remove_permission(base_url, custom_role, role_id, permission_json): print(f"Error occurred during API request: {str(e)}") def update_custom_role(base_url, custom_role, role_id, role_name, role_description, inherited_from): + """ + Updates a custom role. + + Args: + base_url (str): The base URL of the API. + custom_role (CustomRole): An instance of the CustomRole class. + role_id (str): The ID of the custom role to update. + role_name (str): The updated name of the custom role. + role_description (str): The updated description of the custom role. + inherited_from (str): The updated source from which the custom role inherits permissions. + """ try: # Update a custom role update_custom_role_response = custom_role._update_custom_role( @@ -75,6 +130,14 @@ def update_custom_role(base_url, custom_role, role_id, role_name, role_descripti print(f"Error occurred during API request: {str(e)}") def delete_custom_role(base_url, custom_role, role_id): + """ + Deletes a custom role. + + Args: + base_url (str): The base URL of the API. + custom_role (CustomRole): An instance of the CustomRole class. + role_id (str): The ID of the custom role to delete. + """ try: # Delete the custom role delete_role_response = custom_role._delete_custom_role( @@ -91,4 +154,5 @@ def delete_custom_role(base_url, custom_role, role_id): # Instantiate the CustomRole class with your credentials custom_role = CustomRole(username, api_key) + # Retrieve details of all roles in the organization get_all_roles(base_url, custom_role) diff --git a/wandb-scim/examples/teams_example.py b/wandb-scim/examples/teams_example.py index 900d9223..de51caf2 100644 --- a/wandb-scim/examples/teams_example.py +++ b/wandb-scim/examples/teams_example.py @@ -1,9 +1,20 @@ +# calling_module.py + import requests import sys sys.path.append('../') from teams import Teams # Assuming the Teams class is defined in teams.py def create_team(base_url, teams, display_name, member_id): + """ + Creates a new team. + + Args: + base_url (str): The base URL of the API. + teams (Teams): An instance of the Teams class. + display_name (str): The display name of the new team. + member_id (str): The ID of the member to be added to the team. + """ try: # Create a new team create_team_response = teams._create_team( @@ -18,6 +29,14 @@ def create_team(base_url, teams, display_name, member_id): print(f"Error occurred during API request: {str(e)}") def get_team(base_url, teams, team_id): + """ + Retrieves details of a specific team. + + Args: + base_url (str): The base URL of the API. + teams (Teams): An instance of the Teams class. + team_id (str): The ID of the team to retrieve. + """ try: # Get team details get_team_response = teams._get_team(f"{base_url}/Groups/{team_id}") @@ -26,6 +45,13 @@ def get_team(base_url, teams, team_id): print(f"Error occurred during API request: {str(e)}") def get_all_teams(base_url, teams): + """ + Retrieves details of all teams in the organization. + + Args: + base_url (str): The base URL of the API. + teams (Teams): An instance of the Teams class. + """ try: # Get all teams in the organization get_all_teams_response = teams._get_all_teams(f"{base_url}/Groups") @@ -34,6 +60,15 @@ def get_all_teams(base_url, teams): print(f"Error occurred during API request: {str(e)}") def update_team_add_member(base_url, teams, team_id, member_id): + """ + Updates a team by adding a member. + + Args: + base_url (str): The base URL of the API. + teams (Teams): An instance of the Teams class. + team_id (str): The ID of the team to update. + member_id (str): The ID of the member to add to the team. + """ try: # Update team by adding a member update_team_response = teams._add_team( @@ -45,6 +80,15 @@ def update_team_add_member(base_url, teams, team_id, member_id): print(f"Error occurred during API request: {str(e)}") def update_team_remove_member(base_url, teams, team_id, member_id): + """ + Updates a team by removing a member. + + Args: + base_url (str): The base URL of the API. + teams (Teams): An instance of the Teams class. + team_id (str): The ID of the team to update. + member_id (str): The ID of the member to remove from the team. + """ try: # Update team by removing a member update_team_response = teams._remove_team( @@ -62,6 +106,5 @@ def update_team_remove_member(base_url, teams, team_id, member_id): # Instantiate the Teams class with your credentials teams = Teams(username, api_key) - - # Test different methods + # Retrieve details of all teams get_all_teams(base_url, teams) diff --git a/wandb-scim/examples/user_example.py b/wandb-scim/examples/user_example.py index 8ddd223d..b31903f3 100644 --- a/wandb-scim/examples/user_example.py +++ b/wandb-scim/examples/user_example.py @@ -6,6 +6,15 @@ from users import User # Assuming the User class is defined in user_module.py def create_user(base_url, user, email, name): + """ + Creates a new user. + + Args: + base_url (str): The base URL of the API. + user (User): An instance of the User class. + email (str): The email address of the new user. + name (str): The name of the new user. + """ try: # Create a new user create_user_response = user._create_user( @@ -17,6 +26,14 @@ def create_user(base_url, user, email, name): print(f"Error occurred during API request: {str(e)}") def get_user(base_url, user, user_id): + """ + Retrieves details of a specific user. + + Args: + base_url (str): The base URL of the API. + user (User): An instance of the User class. + user_id (str): The ID of the user to retrieve. + """ try: # Get user details get_user_response = user._get_user(f"{base_url}/Users/{user_id}") @@ -25,6 +42,13 @@ def get_user(base_url, user, user_id): print(f"Error occurred during API request: {str(e)}") def get_all_users(base_url, user): + """ + Retrieves details of all users in the organization. + + Args: + base_url (str): The base URL of the API. + user (User): An instance of the User class. + """ try: # Get all users in the organization get_all_users_response = user._get_all_user(f"{base_url}/Users") @@ -33,6 +57,14 @@ def get_all_users(base_url, user): print(f"Error occurred during API request: {str(e)}") def deactivate_user(base_url, user, user_id): + """ + Deactivates a user. + + Args: + base_url (str): The base URL of the API. + user (User): An instance of the User class. + user_id (str): The ID of the user to deactivate. + """ try: # Deactivate a user deactivate_user_response = user._deactivate_user(f"{base_url}/Users/{user_id}") @@ -41,6 +73,15 @@ def deactivate_user(base_url, user, user_id): print(f"Error occurred during API request: {str(e)}") def assign_role_user(base_url, user, user_id, role_name): + """ + Assigns a role to a user. + + Args: + base_url (str): The base URL of the API. + user (User): An instance of the User class. + user_id (str): The ID of the user to assign the role to. + role_name (str): The name of the role to assign. + """ try: # Assign a role to the user assign_role_response = user._assign_role_user( @@ -53,6 +94,16 @@ def assign_role_user(base_url, user, user_id, role_name): def assign_team_user(base_url, user, user_id, team_name, role_name): + """ + Assigns a team role to a user. + + Args: + base_url (str): The base URL of the API. + user (User): An instance of the User class. + user_id (str): The ID of the user to assign the team role to. + team_name (str): The name of the team to assign the role from. + role_name (str): The name of the role to assign. + """ try: # Assign team role to a user assign_team_role_response = user._assign_role_team( @@ -71,4 +122,5 @@ def assign_team_user(base_url, user, user_id, team_name, role_name): # Instantiate the User class with your credentials user = User(username, api_key) + # Retrieve details of all users in the organization get_all_users(base_url, user) diff --git a/wandb-scim/teams.py b/wandb-scim/teams.py index 383be7bd..0f2eae46 100644 --- a/wandb-scim/teams.py +++ b/wandb-scim/teams.py @@ -3,126 +3,186 @@ class Teams(object): def __init__(self, username, api_key): - + """ + Initializes the Teams object with username and API key. + + Args: + username (str): The username for authentication. + api_key (str): The API key for authentication. + """ + # Encode the username and API key into a base64-encoded string for Basic Authentication auth_str = f"{username}:{api_key}" auth_bytes = auth_str.encode('ascii') self.auth_token = base64.b64encode(auth_bytes).decode('ascii') + # Create the authorization header for API requests self.authorization_header = f"Basic {self.auth_token}" def _create_team(self, url, request_payload): + """ + Creates a new team. + + Args: + url (str): The URL for the team creation endpoint. + request_payload (dict): The payload containing team data. + It should contain the following keys: + - 'displayName': The display name of the team. + - 'member': The member to be added to the team. + + Returns: + str: A message indicating whether the team creation was successful or failed. + """ print("Creating the team") data = { - "schemas": ["urn:ietf:params:scim:schemas:core:2.0:Group"], - "displayName": request_payload['displayName'], - "members": [ - { - "value": request_payload['member'] - } - ] - } + "schemas": ["urn:ietf:params:scim:schemas:core:2.0:Group"], + "displayName": request_payload['displayName'], + "members": [ + { + "value": request_payload['member'] + } + ] + } headers = { - "Authorization": self.authorization_header, - "Content-Type": "application/json" + "Authorization": self.authorization_header, + "Content-Type": "application/json" } - response = requests.post(url, json=data , headers=headers) + # Send a POST request to create the team + response = requests.post(url, json=data, headers=headers) if response.status_code == 201: - return "team has been created!" - return f"team creation failed. Status code: {response.status_code}" - + return "Team has been created!" + return f"Team creation failed. Status code: {response.status_code}" + def _get_team(self, url): - print("Getting the team") + """ + Retrieves team details. + Args: + url (str): The URL for the team retrieval endpoint. + + Returns: + str: A message containing team details or indicating failure. + """ + print("Getting the team") headers = { - "Authorization": self.authorization_header, - "Content-Type": "application/json" + "Authorization": self.authorization_header, + "Content-Type": "application/json" } - + # Send a GET request to retrieve the team response = requests.get(url, headers=headers) if response.status_code == 200: - return f"team details: {response.text}" + return f"Team details: {response.text}" return f"Get team failed. Status code: {response.status_code}" def _get_all_teams(self, url): - print("Getting all the teams in org") + """ + Retrieves details of all teams in the organization. + Args: + url (str): The URL for the endpoint to get all teams. + + Returns: + str: A message containing details of all teams or indicating failure. + """ + print("Getting all the teams in org") headers = { - "Authorization": self.authorization_header, - "Content-Type": "application/json" + "Authorization": self.authorization_header, + "Content-Type": "application/json" } - + # Send a GET request to retrieve all teams response = requests.get(url, headers=headers) if response.status_code == 200: - return f"teams details: {response.text}" + return f"Teams details: {response.text}" return f"Get teams failed. Status code: {response.status_code}" def _add_team(self, url, request_payload): - - print("Update team") + """ + Adds a member to the team. + + Args: + url (str): The URL for the endpoint to add a member to the team. + request_payload (dict): The payload containing member information. + It should contain the following key: + - 'value': The value of the member to be added to the team. + + Returns: + str: A message indicating whether the member addition was successful or failed. + """ + print("Adding member to the team") data = { - "schemas": ["urn:ietf:params:scim:api:messages:2.0:PatchOp"], - "Operations": [ - { - "op": "add", - "path": "members", - "value": [ - { - "value": request_payload['value'], - } + "schemas": ["urn:ietf:params:scim:api:messages:2.0:PatchOp"], + "Operations": [ + { + "op": "add", + "path": "members", + "value": [ + { + "value": request_payload['value'], + } ] - } - ] - } + } + ] + } headers = { - "Authorization": self.authorization_header, - "Content-Type": "application/json" + "Authorization": self.authorization_header, + "Content-Type": "application/json" } - + # Send a PATCH request to add the member to the team response = requests.patch(url, json=data, headers=headers) if response.status_code == 200: updated_data = response.json() # Get the updated resource data from the response print("Updated Data:", updated_data) - return "team updated successfully" + return "Team updated successfully" elif response.status_code == 404: - return "team not found" + return "Team not found" else: return f"Failed to update team. Status code: {response.status_code}" def _remove_team(self, url, request_payload): - - print("Update team") + """ + Removes a member from the team. + + Args: + url (str): The URL for the endpoint to remove a member from the team. + request_payload (dict): The payload containing member information. + It should contain the following key: + - 'value': The value of the member to be removed from the team. + + Returns: + str: A message indicating whether the member removal was successful or failed. + """ + print("Removing member from the team") data = { - "schemas": ["urn:ietf:params:scim:api:messages:2.0:PatchOp"], - "Operations": [ - { - "op": "remove", - "path": "members", - "value": [ - { - "value": request_payload['value'], - } + "schemas": ["urn:ietf:params:scim:api:messages:2.0:PatchOp"], + "Operations": [ + { + "op": "remove", + "path": "members", + "value": [ + { + "value": request_payload['value'], + } ] - } - ] - } + } + ] + } headers = { - "Authorization": self.authorization_header, - "Content-Type": "application/json" + "Authorization": self.authorization_header, + "Content-Type": "application/json" } + # Send a PATCH request to remove the member from the team response = requests.patch(url, json=data, headers=headers) if response.status_code == 200: updated_data = response.json() # Get the updated resource data from the response print("Updated Data:", updated_data) - return "team updated successfully" + return "Team updated successfully" elif response.status_code == 404: - return "team not found" + return "Team not found" else: return f"Failed to update team. Status code: {response.status_code}" - \ No newline at end of file diff --git a/wandb-scim/users.py b/wandb-scim/users.py index 5ccd765a..698df6e8 100644 --- a/wandb-scim/users.py +++ b/wandb-scim/users.py @@ -3,13 +3,32 @@ class User(object): def __init__(self, username, api_key): + """ + Initialize User object with username and API key. + + Args: + username (str): The username for authentication. + api_key (str): The API key for authentication. + """ + # Encode the username and API key into a base64-encoded string for Basic Authentication auth_str = f"{username}:{api_key}" auth_bytes = auth_str.encode('ascii') self.auth_token = base64.b64encode(auth_bytes).decode('ascii') + # Create the authorization header for API requests self.authorization_header = f"Basic {self.auth_token}" def _create_user(self, url, request_payload): + """ + Creates a new user. + + Args: + url (str): The URL for the user creation endpoint. + request_payload (dict): The payload containing user data. + + Returns: + str: A message indicating whether the user creation was successful or failed. + """ print("Creating the User") data = { "schemas": [ @@ -27,17 +46,28 @@ def _create_user(self, url, request_payload): "Authorization": self.authorization_header, "Content-Type": "application/json" } + # Send a POST request to create the user response = requests.post(url, json=data, headers=headers) if response.status_code == 201: return "User has been created!" return f"User creation failed. Status code: {response.status_code}" def _get_user(self, url): + """ + Retrieves user details. + + Args: + url (str): The URL for the user retrieval endpoint. + + Returns: + str: A message containing user details or indicating failure. + """ print("Getting the User") headers = { "Authorization": self.authorization_header, "Content-Type": "application/json" } + # Send a GET request to retrieve the user response = requests.get(url, headers=headers) if response.status_code == 200: @@ -45,11 +75,21 @@ def _get_user(self, url): return f"Get user failed. Status code: {response.status_code}" def _get_all_user(self, url): + """ + Retrieves details of all users in the organization. + + Args: + url (str): The URL for the endpoint to get all users. + + Returns: + str: A message containing details of all users or indicating failure. + """ print("Getting all the Users in org") headers = { "Authorization": self.authorization_header, "Content-Type": "application/json" } + # Send a GET request to retrieve all users response = requests.get(url, headers=headers) if response.status_code == 200: @@ -57,11 +97,21 @@ def _get_all_user(self, url): return f"Get users failed. Status code: {response.status_code}" def _deactivate_user(self, url): + """ + Deactivates a user. + + Args: + url (str): The URL for the user deactivation endpoint. + + Returns: + str: A message indicating whether the user deactivation was successful or failed. + """ print("deleting the User") headers = { "Authorization": self.authorization_header, "Content-Type": "application/json" } + # Send a DELETE request to deactivate the user response = requests.delete(url, headers=headers) if response.status_code == 204: @@ -72,7 +122,18 @@ def _deactivate_user(self, url): return f"Failed to delete user. Status code: {response.status_code}" def _assign_role_user(self, url, request_payload): - # request_payload[role] It can be one of admin, viewer or member. + """ + Assigns a role to a user. + + Args: + url (str): The URL for the endpoint to assign a role to the user. + request_payload (dict): The payload containing role information. + It should contain the following key: + - 'roleName': The role to be assigned to the user. It can be one of 'admin', 'viewer', or 'member'. + + Returns: + str: A message indicating whether the role assignment was successful or failed. + """ print("Assign a role to the User") data = { "schemas": ["urn:ietf:params:scim:api:messages:2.0:PatchOp"], @@ -88,10 +149,8 @@ def _assign_role_user(self, url, request_payload): "Authorization": self.authorization_header, "Content-Type": "application/json" } - print(url) - print(data) + # Send a PATCH request to assign the role to the user response = requests.patch(url, json=data, headers=headers) - print(response.text) if response.status_code == 200: updated_data = response.json() # Get the updated resource data from the response print("Updated Data:", updated_data) @@ -102,6 +161,16 @@ def _assign_role_user(self, url, request_payload): return f"Failed to update user. Status code: {response.status_code}" def _assign_role_team(self, url, request_payload): + """ + Assigns a role to a user of the team. + + Args: + url (str): The URL for the endpoint to assign a role to the user of the team. + request_payload (dict): The payload containing role information. + + Returns: + str: A message indicating whether the role assignment was successful or failed. + """ print("assign a role to the User of the team") data = { "schemas": ["urn:ietf:params:scim:api:messages:2.0:PatchOp"], @@ -122,7 +191,7 @@ def _assign_role_team(self, url, request_payload): "Authorization": self.authorization_header, "Content-Type": "application/json" } - + # Send a PATCH request to assign the role to the user of the team response = requests.patch(url, json=data, headers=headers) if response.status_code == 200: