"""Interface for the ows-carveouts microservice.""" from oto import response from owsrequest import request as requests import sentry_sdk from ows_product_physical.constant import error from ows_product_physical.constant import field from ows_product_physical.constant import service_name def set_carveins_for_physical_product(product_id, vendor_id): """Set the vendor default carveins for a physical product. Args: product_id (int): product id to set carveins for. vendor_id (int): vendor id to set carveins from. Returns: Response: Response containing the carvein information. """ try: carvein_response = requests.post( service_name.OWS_CARVEOUTS, '/carveout/product/{}/carveout-default-phys-dms'.format( product_id), data={field.VENDOR_ID: vendor_id}) if carvein_response.status_code != 200: return response.create_error_response( code=error.CARVEIN_ERROR, message=carvein_response.reason, status=carvein_response.status_code) return response.Response(status=carvein_response.status_code) except Exception as exception: sentry_sdk.capture_exception(exception) return response.create_error_response( code=error.INTERNAL_ERROR, message='connection error', status=500) def get_release_carveouts_for_upc(upc): """Get the release carveouts for upc. Args: upc (int): the upc Returns: Response: Response containing the carvein information. """ try: carveout_response = requests.get( service_name.OWS_CARVEOUTS, '/carveout/release/{}/dms'.format(upc), ) if carveout_response.status_code != 200: return response.create_error_response( code=error.CARVEIN_ERROR, message=carveout_response.reason, status=carveout_response.status_code) return response.Response(message=carveout_response.json()) except Exception as exception: sentry_sdk.capture_exception(exception) return response.create_error_response( code=error.INTERNAL_ERROR, message='connection error', status=500)