"""Interface to the ows-product microservice.""" from owsrequest import request from owsresponse import response from asset_file_details.constants import account from asset_file_details.constants import error from asset_file_details.constants import services def check_ownership(upc, account_type, account_id, correlation_id): """Check if product is owned by the given account. Args: upc (str): upc account_type (str): type of account (vendor or subaccount) account_id (int): id of the account to check correlation_id (str): correlation id for logs Returns: response.Response: status code 200 if owner, 403 if not owner """ if account_type not in [account.VENDOR_TYPE, account.SUBACCOUNT_TYPE]: return response.create_error_response( code=error.ERROR_CODE_BAD_REQUEST, message='Invalid account type', status=400) resource = '/{account_type}/{account_id}/upcs'.format( account_type=account_type, account_id=account_id) ows_product_response = request.post( services.OWS_PRODUCT, resource, correlation_id=correlation_id, json={'upcs': upc}) 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)