"""Interface for the ows-users microservice.""" import uuid from ddtrace import tracer from owsrequest import request as requests from owsresponse import response from account.constants import error, service from account.models.types import ProfileInfo def get_user_details(user_id): """Get a user from ows-users. Args: user_id (str): the orchard user id Returns: response.Response: containing the user. """ path = '/users/{}'.format(user_id) result = requests.get(service.OWS_USERS, path) if result.status_code != 200: return response.create_error_response( status=result.status_code, code=error.ERROR_CODE_OWS_USERS_REQUEST, message=result.text, ) return response.Response(result.json()) @tracer.wrap() def get_user_profiles_by_identity_id(identity_id: uuid.UUID) -> list[ProfileInfo] | None: """Get a user profiles from ows-users. Args: identity_id (str): the Neo4j identity id Returns: list[ProfileInfo]: A list of profiles that user has access to. """ path = '/users/identity/{}/profiles'.format(identity_id) result = requests.get(service.OWS_USERS, path) if result.status_code != 200: return None items = result.json().get('items', []) profiles = [ ProfileInfo( profile_type=item['profile_type'], profile_id=item['profile_id'], roles=item.get('roles', []), uuid=item['uuid'], ) for item in items ] return profiles