-
-
Notifications
You must be signed in to change notification settings - Fork 260
Api v2 create alert filter #946
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Elise17
wants to merge
30
commits into
develop
Choose a base branch
from
api_v2_create_alert_filter
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
54932da
Moved code into persistence layer
c8y3 8c18603
Import logger directly
c8y3 2f8e1ce
Reuse method
c8y3 a6ef962
Extracted method
c8y3 c205de7
Started implementation of POST /api/v2/manage/customers
c8y3 5335c51
Create customer should allow to set customer_name
c8y3 ee4a875
Create customer should return 400 when another customer with the same…
c8y3 5611cbc
Fixed regression
c8y3 9fdaf1e
POST /api/v2/manage/customers adds an activity
c8y3 06d65fd
Fixed incorrect test
c8y3 5e4b536
POST /api/v2/manage/customers adds user to customer
c8y3 d4a6b49
Fixed ruff warning
c8y3 e36816a
Deprecated POST /manage/customers/add
c8y3 70fd435
Changed branch alert_similarities
Elise17 3b9a545
Changed test rest alerts
Elise17 afde506
Changed import from the API layer
Elise17 c99d817
Fixed check analysis
Elise17 7f3dcd7
changed message api error
Elise17 2f1a1d4
Removed unused function
Elise17 0516cc4
Removed import
Elise17 9a33abf
Started implementation of POST /api/v2/alerts-filters
Elise17 b7088fd
Fixed analysis check
Elise17 103ed2c
Added function _load
Elise17 82bfec6
Deprecated endpoint POST /filters/add in favor of POST /api/v2/alerts…
Elise17 5b1290e
Added test create alert when filter data is missing
Elise17 ea45b99
Added test test_create_alert_filter_should_return_filter_type
Elise17 4c5ddd6
Added test_create_alert_filter_should_return_filter_name
Elise17 0a0f63d
Added test_create_alert_filter_should_return_in_filter_data_alert_title
Elise17 7a24e1e
Fixed problem with filter_id
Elise17 b898352
Fixed static analysis
Elise17 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,60 @@ | ||
| # 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 marshmallow import ValidationError | ||
|
|
||
| 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_error | ||
| from app.blueprints.iris_user import iris_current_user | ||
| from app.schema.marshables import SavedFilterSchema | ||
|
|
||
| from app.business.alerts_filters import alerts_filters_add | ||
|
|
||
|
|
||
| class AlertsFiltersOperations: | ||
|
|
||
| def __init__(self): | ||
| self._schema = SavedFilterSchema() | ||
|
|
||
| def _load(self, request_data): | ||
| return self._schema.load(request_data) | ||
|
|
||
| def create(self): | ||
| request_data = request.get_json() | ||
| request_data ['created_by'] = iris_current_user.id | ||
|
|
||
| try: | ||
| new_saved_filter = self._load(request_data) | ||
| alerts_filters_add(new_saved_filter) | ||
| return response_api_created(self._schema.dump(new_saved_filter)) | ||
|
|
||
| except ValidationError as e: | ||
| return response_api_error('Data error', e.messages) | ||
|
|
||
|
|
||
| alerts_filters_blueprint = Blueprint('alerts_filters_rest_v2', __name__, url_prefix='/alerts-filters') | ||
| alerts_filters_operations = AlertsFiltersOperations() | ||
|
|
||
|
|
||
| @alerts_filters_blueprint.post('') | ||
| @ac_api_requires() | ||
| def create_alert_filter(): | ||
| return alerts_filters_operations.create() | ||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an unnecessary space before the opening bracket. Change
request_data ['created_by']torequest_data['created_by']for consistent Python spacing conventions.