"""Model for ows-product.""" import logging import requests import config # noqa import const # noqa from models.api_exceptions import PersistentException logger = logging.getLogger() logger.setLevel(logging.INFO) def get_product_info(product_id, session=requests): """Get product info. Args: product_id: The id of the product to get data for. session: Session object to make requests with. The default is the requests module because it creates a Session object internally and has the same interface. """ url = const.get_service_url( environment=config.ENVIRONMENT, service_name=const.OWS_PRODUCT_SERVICE_NAME, path=const.OWS_PRODUCT_GET_PRODUCT_ENDPOINT.format(product_id)) response = session.get(url, timeout=10) if response.status_code == 404: logger.error('Requested product not found.') raise PersistentException(response.text) if response.status_code != 200: logger.error('Unable to fetch product information from ows-product.') raise PersistentException(response.text) logging.info('get_product_info success. Data: {}'.format(response.text)) return response.json()