-
-
Notifications
You must be signed in to change notification settings - Fork 150
Bring targets out of alerts #1353
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2b53b88
Bring targets out of alerts
parmesant 484a0c7
Integrated Targets with Alerts
parmesant cd363c2
Merge branch 'main' into targets-separation
parmesant cd39b98
Updates: Coderabbit suggestions and validations
parmesant 68de9f0
update: add name to target
parmesant 0f7c879
Merge branch 'main' into targets-separation
nikhilsinhaparseable b9ed392
bugfix: coderabbit suggestion
parmesant b764f26
bugfix: ignore settings directory for list stream
parmesant 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,92 @@ | ||
use actix_web::{ | ||
web::{self, Json, Path}, | ||
HttpRequest, Responder, | ||
}; | ||
use bytes::Bytes; | ||
use ulid::Ulid; | ||
|
||
use crate::{ | ||
alerts::{ | ||
target::{Target, TARGETS}, | ||
AlertError, | ||
}, | ||
parseable::PARSEABLE, | ||
storage::object_storage::target_json_path, | ||
}; | ||
|
||
// POST /targets | ||
pub async fn post( | ||
_req: HttpRequest, | ||
Json(target): Json<Target>, | ||
) -> Result<impl Responder, AlertError> { | ||
// should check for duplicacy and liveness (??) | ||
target.validate().await; | ||
nitisht marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
let path = target_json_path(target.id); | ||
|
||
let store = PARSEABLE.storage.get_object_store(); | ||
let target_bytes = serde_json::to_vec(&target)?; | ||
store.put_object(&path, Bytes::from(target_bytes)).await?; | ||
|
||
// add to the map | ||
TARGETS.update(target.clone()).await?; | ||
|
||
Ok(web::Json(target)) | ||
} | ||
|
||
// GET /targets | ||
pub async fn list(_req: HttpRequest) -> Result<impl Responder, AlertError> { | ||
// add to the map | ||
let list = TARGETS.list().await?; | ||
|
||
Ok(web::Json(list)) | ||
} | ||
|
||
// GET /targets/{target_id} | ||
pub async fn get(_req: HttpRequest, target_id: Path<Ulid>) -> Result<impl Responder, AlertError> { | ||
let target_id = target_id.into_inner(); | ||
|
||
let target = TARGETS.get_target_by_id(&target_id).await?; | ||
|
||
Ok(web::Json(target)) | ||
} | ||
|
||
// PUT /targets/{target_id} | ||
pub async fn update( | ||
_req: HttpRequest, | ||
target_id: Path<Ulid>, | ||
Json(mut target): Json<Target>, | ||
) -> Result<impl Responder, AlertError> { | ||
let target_id = target_id.into_inner(); | ||
|
||
// if target_id does not exist, error | ||
TARGETS.get_target_by_id(&target_id).await?; | ||
|
||
// esnure that the supplied target id is assigned to the target config | ||
target.id = target_id; | ||
// should check for duplicacy and liveness (??) | ||
target.validate().await; | ||
|
||
let path = target_json_path(target.id); | ||
|
||
let store = PARSEABLE.storage.get_object_store(); | ||
let target_bytes = serde_json::to_vec(&target)?; | ||
store.put_object(&path, Bytes::from(target_bytes)).await?; | ||
|
||
// add to the map | ||
TARGETS.update(target.clone()).await?; | ||
|
||
Ok(web::Json(target)) | ||
} | ||
|
||
// DELETE /targets/{target_id} | ||
pub async fn delete( | ||
_req: HttpRequest, | ||
target_id: Path<Ulid>, | ||
) -> Result<impl Responder, AlertError> { | ||
let target_id = target_id.into_inner(); | ||
|
||
let target = TARGETS.delete(&target_id).await?; | ||
|
||
Ok(web::Json(target)) | ||
} | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
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.
Uh oh!
There was an error while loading. Please reload this page.