-
-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MRG] Merge pull request #611 from dfir-iris/apiv2_new_dir
Apiv2 new dir
- Loading branch information
Showing
11 changed files
with
254 additions
and
222 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
api_v2_url_prefix="/api/v2/" |
Empty file.
81 changes: 81 additions & 0 deletions
81
source/app/blueprints/rest/v2/case/api_v2_assets_routes.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# IRIS Source Code | ||
# Copyright (C) 2024 - DFIR-IRIS | ||
# [email protected] | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU Lesser General Public | ||
# License as published by the Free Software Foundation; either | ||
# version 3 of the License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
# Lesser General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser General Public License | ||
# along with this program; if not, write to the Free Software Foundation, | ||
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
|
||
from flask import Blueprint | ||
from flask import request | ||
|
||
from app.blueprints.access_controls import ac_api_requires | ||
from app.blueprints.rest.endpoints import response_api_created | ||
from app.blueprints.rest.endpoints import response_api_deleted | ||
from app.blueprints.rest.endpoints import response_api_error | ||
from app.blueprints.rest.endpoints import response_api_success | ||
from app.business.assets import assets_create | ||
from app.business.assets import assets_delete | ||
from app.business.assets import assets_get | ||
from app.business.errors import BusinessProcessingError | ||
from app.iris_engine.access_control.utils import ac_fast_check_current_user_has_case_access | ||
from app.models.authorization import CaseAccessLevel | ||
from app.schema.marshables import CaseAssetsSchema | ||
from app.util import ac_api_return_access_denied | ||
|
||
api_v2_assets_blueprint = Blueprint('case_assets_rest_v2', | ||
__name__, | ||
url_prefix='/api/v2') | ||
|
||
|
||
@api_v2_assets_blueprint.route('/cases/<int:identifier>/assets', methods=['POST']) | ||
@ac_api_requires() | ||
def add_asset(identifier): | ||
if not ac_fast_check_current_user_has_case_access(identifier, [CaseAccessLevel.full_access]): | ||
return ac_api_return_access_denied(caseid=identifier) | ||
|
||
asset_schema = CaseAssetsSchema() | ||
try: | ||
_, asset = assets_create(identifier, request.get_json()) | ||
return response_api_created(asset_schema.dump(asset)) | ||
except BusinessProcessingError as e: | ||
return response_api_error(e.get_message()) | ||
|
||
|
||
@api_v2_assets_blueprint.route('/assets/<int:identifier>', methods=['GET']) | ||
@ac_api_requires() | ||
def asset_view(identifier): | ||
asset_schema = CaseAssetsSchema() | ||
|
||
try: | ||
asset = assets_get(identifier) | ||
if not ac_fast_check_current_user_has_case_access(asset.case_id, [CaseAccessLevel.read_only, CaseAccessLevel.full_access]): | ||
return ac_api_return_access_denied(caseid=asset.case_id) | ||
|
||
return response_api_success(asset_schema.dump(asset)) | ||
except BusinessProcessingError as e: | ||
return response_api_error(e.get_message()) | ||
|
||
|
||
@api_v2_assets_blueprint.route('/assets/<int:identifier>', methods=['DELETE']) | ||
@ac_api_requires() | ||
def asset_delete(identifier): | ||
try: | ||
asset = assets_get(identifier) | ||
if not ac_fast_check_current_user_has_case_access(asset.case_id, [CaseAccessLevel.full_access]): | ||
return ac_api_return_access_denied(caseid=asset.case_id) | ||
|
||
assets_delete(asset) | ||
return response_api_deleted() | ||
except BusinessProcessingError as e: | ||
return response_api_error(e.get_message()) |
Oops, something went wrong.