"""Interface for ows-product microservice.""" import backoff import requests import config from src.constants import services as services_consts from src.utils import detect_retriable_error, is_not_found_http_error, log_execution @detect_retriable_error @log_execution @backoff.on_exception(backoff.expo, requests.exceptions.HTTPError, max_tries=3, giveup=is_not_found_http_error) def get_product(product_id): """Get information about product. Args: product_id (int): product id. Returns: dict: information about product. Raises: requests.exceptions.HTTPError: When 400 <= status_code < 600 """ url = _get_ows_product_url(product_id) response = requests.get(url) response.raise_for_status() return response.json() def _get_ows_product_url(product_id): """Get url to ows-product for the product id.""" return services_consts.SERVICE_URL.format( environment=config.ENVIRONMENT, service_name=services_consts.OWS_PRODUCT_SERVICE_NAME, path=services_consts.OWS_PRODUCT_ENDPOINT.format(product_id), )