"""Account based helpers methods.""" from fastapi import HTTPException from moneyhub.constants.constants import ITEMS_KEY from moneyhub.constants.error import ACCOUNTS_DOES_NOT_EXIST from moneyhub.constants.error import UNEXPECTED_OWS_RESPONSE from moneyhub.utils.owsclient import get SERVICE_NAME = 'ows-permissions' def get_resources_for_profile(orchard_profile_type: str, orchard_profile_id: int) -> list: """Get resources for a given profile. Args: orchard_profile_type (str): Type of profile orchard_profile_id (str): Profile Identifier Returns: list: List of account ids """ endpoint = f'/admin/profile-type/{orchard_profile_type}/profile/{orchard_profile_id}' \ f'/resource/all' result = get(SERVICE_NAME, endpoint) data = result.json() if not data or ITEMS_KEY not in data: raise KeyError(UNEXPECTED_OWS_RESPONSE.format(service=SERVICE_NAME, response=result.text)) items = data['items'] if not items: raise HTTPException(status_code=404, detail=ACCOUNTS_DOES_NOT_EXIST) return items