暂无描述

assets.py 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # IRIS Source Code
  2. # Copyright (C) 2024 - DFIR-IRIS
  3. # contact@dfir-iris.org
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU Lesser General Public
  7. # License as published by the Free Software Foundation; either
  8. # version 3 of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. # Lesser General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Lesser General Public License
  16. # along with this program; if not, write to the Free Software Foundation,
  17. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. from flask import Blueprint
  19. from app.blueprints.access_controls import ac_api_requires
  20. from app.blueprints.rest.endpoints import response_api_deleted
  21. from app.blueprints.rest.endpoints import response_api_error
  22. from app.blueprints.rest.endpoints import response_api_success
  23. from app.blueprints.rest.endpoints import response_api_not_found
  24. from app.business.assets import assets_delete
  25. from app.business.assets import assets_get
  26. from app.business.errors import BusinessProcessingError
  27. from app.business.errors import ObjectNotFoundError
  28. from app.iris_engine.access_control.utils import ac_fast_check_current_user_has_case_access
  29. from app.models.authorization import CaseAccessLevel
  30. from app.schema.marshables import CaseAssetsSchema
  31. from app.blueprints.access_controls import ac_api_return_access_denied
  32. assets_blueprint = Blueprint('assets_api_v2',
  33. __name__,
  34. url_prefix='/assets')
  35. @assets_blueprint.get('/<int:identifier>')
  36. @ac_api_requires()
  37. def get_asset(identifier):
  38. asset_schema = CaseAssetsSchema()
  39. try:
  40. asset = assets_get(identifier)
  41. # perform authz check
  42. if not ac_fast_check_current_user_has_case_access(asset.case_id, [CaseAccessLevel.read_only, CaseAccessLevel.full_access]):
  43. return ac_api_return_access_denied(caseid=asset.case_id)
  44. return response_api_success(asset_schema.dump(asset))
  45. except ObjectNotFoundError:
  46. return response_api_not_found()
  47. except BusinessProcessingError as e:
  48. return response_api_error(e.get_message())
  49. @assets_blueprint.delete('/<int:identifier>')
  50. @ac_api_requires()
  51. def delete_asset(identifier):
  52. try:
  53. asset = assets_get(identifier)
  54. # perform authz check
  55. if not ac_fast_check_current_user_has_case_access(asset.case_id, [CaseAccessLevel.full_access]):
  56. return ac_api_return_access_denied(caseid=asset.case_id)
  57. assets_delete(asset)
  58. return response_api_deleted()
  59. except ObjectNotFoundError:
  60. return response_api_not_found()
  61. except BusinessProcessingError as e:
  62. return response_api_error(e.get_message())