""" Interface to the manage asset service. The model is responsible for making calls to a legacy manage asset service. It makes a request to manage asset endpoints ('/asset/delete', methods=['POST']) and returns a result of the request. """ import json from oto import response import requests from assets import config from assets.connectors.sentry import sentry_client from assets.constants import error from assets.constants import service def delete_assets(asset_filenames, asset_type_id): """Delete assets by asset name and asset type id. Args: asset_filenames (list(str)): file names of assets to delete. asset_type_id (int): asset type id. Returns: response.Response: Track details in response message or error response. """ try: resource = service.MANAGE_ASSET_DELETE.format( service_url=config.MANAGE_ASSET_URL) request_data = { 'files': asset_filenames, 'asset_type_id': asset_type_id, 'physical_location_id': config.SERVER_LOCATION_AVL } manage_asset_response = requests.post( resource, json=json.dumps(request_data)) except Exception as ex: sentry_client.captureException() return response.create_error_response( code=error.INTERNAL_ERROR, message=str(ex), status=500) if manage_asset_response.status_code == 200: return response.Response(message=error.SUCCESS_CODE) if manage_asset_response.status_code == 404: return response.create_not_found_response( message=error.ERROR_ASSET_NOT_FOUND) return response.create_fatal_response()