"""Interface for ows-account microservice.""" import backoff import requests import config from src.constants import services as services_consts from src.utils import is_not_found_http_error, log_execution @log_execution @backoff.on_exception(backoff.expo, requests.exceptions.HTTPError, max_tries=3, giveup=is_not_found_http_error) def is_distributor(vendor_id): """Return whether the vendor id is a distributor. Args: vendor_id (int): vendor id. Returns: bool: distributor or not. Raises: requests.exceptions.HTTPError: When 400 <= status_code < 600 """ url = _get_is_distributor_url(vendor_id) response = requests.head(url) response.raise_for_status() return response.status_code == 200 def _get_is_distributor_url(vendor_id): """Get url to ows-account for distributor endpoint.""" return services_consts.SERVICE_URL.format( environment=config.ENVIRONMENT, service_name=services_consts.OWS_ACCOUNT_SERVICE_NAME, path=services_consts.VENDOR_IS_DISTRIBUTOR_ENDPOINT.format(vendor_id), )