"""Interface to the ows-permissions microservice.""" from ddtrace import tracer from oto import response as oto_response from sound_recordings.constants import service as service_constants from sound_recordings.services import request ARTIST_INFO_RESOURCE = "artistinfo" LABEL_RESOURCE = "label" ALL_RESOURCE = "all" ARTIST_INFO_RESOURCE_TYPE = "ArtistInfo" SUBACCOUNT_RESOURCE_TYPE = "Subaccount" VENDOR_RESOURCE_TYPE = "Vendor" def _get_resources(profile_type, profile_id, resource): """Get resources. Args: profile_type (str): The profile type. profile_id (int): The profile id. resource (str): The resource to retrieve. Returns: oto.response.Response with resources. """ ows_permissions_response = request.get( service_constants.OWS_PERMISSIONS, service_constants.OWS_PERMISSIONS_PROFILE_RESOURCE.format( profile_type=profile_type, profile_id=profile_id, resource=resource ), ) if ows_permissions_response.status_code != 200: return oto_response.Response(status=ows_permissions_response.status_code) json = ows_permissions_response.json() return oto_response.Response(message=json) @tracer.wrap(name="get_artist_info_resources") def get_artist_info_resources(profile_type, profile_id): """Get artist info resources. Args: profile_type (str): The profile type. profile_id (int): The profile id. Returns: oto.response.Response with artist info resources. """ return _get_resources(profile_type, profile_id, ARTIST_INFO_RESOURCE_TYPE) @tracer.wrap(name="get_label_resources") def get_label_resources(profile_type, profile_id): """Get label resources. Args: profile_type (str): The profile type. profile_id (int): The profile id. Returns: oto.response.Response with label resources. """ return _get_resources(profile_type, profile_id, LABEL_RESOURCE) @tracer.wrap(name="get_all_resources") def get_all_resources(profile_type, profile_id): """Get all resources. Args: profile_type (str): The profile type. profile_id (int): The profile id. Returns: oto.response.Response with all resources. """ return _get_resources(profile_type, profile_id, ALL_RESOURCE)