"""Interface to the ows-product microservice.""" from oto import response from owsrequest import request from product_digital_marketing.constants import error from product_digital_marketing.constants import services def check_ownership(product_id, account_type, account_id): """Check if product is owned by the given account. 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: response.Response: status code 200 if owner, 403 if not owner """ if account_type not in ['vendor', 'subaccount']: return response.create_error_response( code=error.ERROR_CODE_BAD_REQUEST, message='Invalid account type', status=400) resource = '/{account_type}/{account_id}/product/{product_id}'.format( account_type=account_type, account_id=account_id, product_id=product_id) ows_product_response = request.head(services.OWS_PRODUCT, resource) if ows_product_response.status_code == 403: return response.create_error_response( code=error.ERROR_CODE_AUTHORIZATION, message=error.ERROR_MESSAGE_NOT_PRODUCT_OWNER, status=403) return response.Response(status=ows_product_response.status_code)