"""Interface for the ows-product microservice.""" from owsrequest import request as requests from owsresponse import response from sentry_sdk import capture_exception from blacklist_manager.constants import error from blacklist_manager.constants import service_name def check_product_ownership(product_id, account_type=None, account_id=None): """Check ownership of a product. Args: product_id: containing a unique identifier of a product id. account_type (str): account type (either “subaccount” or “vendor”). account_id (str): account id. Cannot be empty. Returns: response.Response: result of checking the ownership. """ try: path = f'/{account_type}/{account_id}/product/{product_id}' result = requests.head(service_name.OWS_PRODUCT, path) if result.status_code == 403: return response.create_error_response( status=403, code=error.FORBIDDEN_CODE, message=error.OWNERSHIP_ERROR_MESSAGE.format(account_type)) return response.Response(status=result.status_code) except Exception: capture_exception() return response.create_error_response( code=error.INTERNAL_ERROR, message='connection error', status=500)