"""Interface to the ows-account microservice.""" from oto import response from oto import status as http_status from owsrequest import request from owsrequest.constants.headers import ( ORCHARD_IDENTITY_ID, ORCHARD_PROFILE_ID, ORCHARD_PROFILE_TYPE, ) from sentry_sdk import capture_exception from timed_release.constants import ( error, header, service_name, timed_release_ws, ) def get_stores(request_headers): """Get the active stores for workstation timed release. Args: request_headers (object): Request headers sent in the endpoint call. Returns: response.Response: json data containing list of store objects or errors """ headers = { ORCHARD_PROFILE_TYPE: request_headers[ORCHARD_PROFILE_TYPE], ORCHARD_PROFILE_ID: request_headers[ORCHARD_PROFILE_ID] } bearer_token = request_headers.get(header.AUTHORIZATION) if bearer_token: headers.update({header.AUTHORIZATION: bearer_token}) else: headers.update({ ORCHARD_IDENTITY_ID: request_headers[ORCHARD_IDENTITY_ID] }) try: stores_response = request.get( service_name.OWS_STORE, timed_release_ws.GET_STORES_URL, params={ 'status': [timed_release_ws.DSP_STATUS_ACTIVE] }, headers=headers ) except Exception: capture_exception() return response.create_error_response( code=error.INTERNAL_ERROR, message=error.ERROR_MESSAGE_FETCHING_STORES, status=http_status.INTERNAL_ERROR ) if stores_response.status_code != http_status.OK: return response.create_error_response( code=error.INTERNAL_ERROR, message=error.ERROR_MESSAGE_FETCHING_STORES, status=http_status.INTERNAL_ERROR ) return response.Response( status=http_status.OK, message=stores_response.json()['items'])