Skip to content

Commit dc647ea

Browse files
author
Nivedithaa Mahendran
committed
post instead of patch
1 parent 1139736 commit dc647ea

2 files changed

Lines changed: 230 additions & 75 deletions

File tree

src/mas/devops/users.py

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,10 @@ def mas_workspace_application_ids(self):
193193

194194
def get_user(self, user_id):
195195
"""
196-
Retrieve a user's details from MAS Core API.
196+
Retrieve a user's details from MAS API.
197+
198+
For MAS version >= 9.1, this method uses the Manage API masperuser endpoint.
199+
For earlier versions, it uses the Core API v3/users endpoint.
197200
198201
Args:
199202
user_id (str): The unique identifier of the user to retrieve.
@@ -205,16 +208,39 @@ def get_user(self, user_id):
205208
Exception: If the API returns an unexpected status code.
206209
"""
207210
self.logger.debug(f"Getting user {user_id}")
208-
url = f"{self.mas_api_url_internal}/v3/users/{user_id}"
209-
headers = {
210-
"Accept": "application/json",
211-
"x-access-token": self.superuser_auth_token
212-
}
213-
response = requests.get(
214-
url,
215-
headers=headers,
216-
verify=self.core_internal_ca_pem_file_path
217-
)
211+
212+
# For MAS version >= 9.1, use the Manage API masperuser endpoint
213+
if Version(self.mas_version) >= Version('9.1'):
214+
# Get MAXADMIN API key for authentication
215+
maxadmin_manage_api_key = self.create_or_get_manage_api_key_for_user(MASUserUtils.MAXADMIN, temporary=True)
216+
217+
url = f"{self.manage_api_url_internal}/maximo/api/os/masperuser/{user_id}"
218+
querystring = {
219+
"lean": 1
220+
}
221+
headers = {
222+
"Accept": "application/json",
223+
"apikey": maxadmin_manage_api_key["apikey"]
224+
}
225+
response = requests.get(
226+
url,
227+
headers=headers,
228+
params=querystring,
229+
cert=self.manage_internal_client_pem_file_path,
230+
verify=self.manage_internal_ca_pem_file_path
231+
)
232+
else:
233+
# For earlier versions, use the Core API v3/users endpoint
234+
url = f"{self.mas_api_url_internal}/v3/users/{user_id}"
235+
headers = {
236+
"Accept": "application/json",
237+
"x-access-token": self.superuser_auth_token
238+
}
239+
response = requests.get(
240+
url,
241+
headers=headers,
242+
verify=self.core_internal_ca_pem_file_path
243+
)
218244

219245
if response.status_code == 404:
220246
return None
@@ -358,7 +384,7 @@ def set_user_group_reassignment_auth(self, user_id, groupreassign, manage_api_ke
358384
]
359385
}
360386

361-
response = requests.patch(
387+
response = requests.post(
362388
url,
363389
json=payload,
364390
headers=headers,
@@ -1587,7 +1613,8 @@ def create_initial_user_for_saas(self, user, user_type, groupreassign=None):
15871613
}
15881614

15891615
self.logger.info(f"User def - {user_def}")
1590-
self.get_or_create_user(user_def)
1616+
user_info = self.get_or_create_user(user_def)
1617+
self.logger.info(f"User info - {user_info}")
15911618
self.link_user_to_local_idp(user_id, email_password=True)
15921619
self.add_user_to_workspace(user_id, is_workspace_admin=is_workspace_admin)
15931620

0 commit comments

Comments
 (0)