"""Interface for the ows-product microservice.""" from flask import Response from owsrequest import request from carveouts.constants import error, service_name def check_ownership(product_id: int, account_type: str, account_id: int) -> Response: """Check product ownership for given product id. Args: product_id (int): the id of the product to check account_type (str): type of account (vendor or subaccount) account_id (int): id of the account to check Returns: flask.Response: status code 200 if owner. """ product_ownership_response = request.head( service_name.OWS_PRODUCT, "/{account_type}/{account_id}/product/{product_id}".format( account_type=account_type, account_id=account_id, product_id=product_id ), ) if product_ownership_response.status_code != 200: return Response( response=( f"{error.ERROR_CODE_AUTHORIZATION}: {error.ERROR_MESSAGE_FOR_OWNERSHIP}" ), status=product_ownership_response.status_code, ) return Response(status=product_ownership_response.status_code)