"""Interface to the ows-account microservice.""" from owsrequest import request from ows_accounting import response from ows_accounting.constants import error from ows_accounting.constants import payment_holds VENDOR_CHECK_RESOURCE = '/vendor/{vendor_id}' ACCOUNT_SERVICE = 'ows-account' def check_vendor_exists(vendor_id): """Check if vendor exists with this vendor_id. Args: vendor_id (int): vendor identifier. Returns: response.Response: success or error response. """ resource = VENDOR_CHECK_RESOURCE.format(vendor_id=vendor_id) account_response = request.head(ACCOUNT_SERVICE, resource) if account_response.status_code == 200: return response.Response(message=payment_holds.VENDOR_FOUND_MESSAGE) if account_response.status_code == 404: return response.create_not_found_response( message=payment_holds.VENDOR_NOT_FOUND_MESSAGE) error_response = response.create_fatal_response(account_response.text) response.send_to_sentry( error_response, error.ERROR_CODE_INVALID_RESPONSE_CODE) return error_response