-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dgw): initial implementation of /jet/jrec/list (#412)
My first shot at implementing session recording listing using a scope token. It's just half the work, here's what I don't like about it: - not enough error handling (probably panics if directory is empty) - scope token cannot be reused, not sure how to make it reusable - result is a vector of strings, maybe we'd like a vector of objects - result is not sorted, file creation time sorting would be best
- Loading branch information
1 parent
372d92d
commit 332c86f
Showing
4 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
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,62 @@ | ||
use crate::config::ConfHandle; | ||
use crate::http::guards::access::{AccessGuard, TokenType}; | ||
use crate::http::HttpErrorStatus; | ||
use crate::token::AccessScope; | ||
use saphir::body::json::Json; | ||
use saphir::controller::Controller; | ||
use saphir::http::Method; | ||
use saphir::macros::controller; | ||
use saphir::request::Request; | ||
use std::fs; | ||
use std::path::Path; | ||
use uuid::Uuid; | ||
|
||
pub struct RecordingsController { | ||
pub conf_handle: ConfHandle, | ||
} | ||
|
||
#[controller(name = "jet/jrec/list")] | ||
impl RecordingsController { | ||
#[get("/")] | ||
#[guard(AccessGuard, init_expr = r#"TokenType::Scope(AccessScope::RecordingsRead)"#)] | ||
async fn get_recordings(&self) -> Result<Json<Vec<String>>, HttpErrorStatus> { | ||
get_recordings(&self.conf_handle).await | ||
} | ||
} | ||
|
||
fn list_uuid_dirs(dir_path: &Path) -> Vec<String> { | ||
fs::read_dir(dir_path) | ||
.unwrap() | ||
.filter_map(|entry| { | ||
let path = entry.unwrap().path(); | ||
if path.is_dir() { | ||
path.file_name() | ||
.and_then(|name| Uuid::parse_str(name.to_str().unwrap()).ok()) | ||
.map(|uuid| uuid.to_string()) | ||
} else { | ||
None | ||
} | ||
}) | ||
.collect() | ||
} | ||
|
||
/// Lists recordings | ||
#[cfg_attr(feature = "openapi", utoipa::path( | ||
get, | ||
operation_id = "GetRecordings", | ||
tag = "Recordings", | ||
path = "/jet/jrec/list", | ||
responses( | ||
(status = 200, description = "Recordings for this Gateway", body = Recording), | ||
(status = 400, description = "Bad request"), | ||
(status = 401, description = "Invalid or missing authorization token"), | ||
(status = 403, description = "Insufficient permissions"), | ||
), | ||
security(("scope_token" = ["gateway.recordings.read"])), | ||
))] | ||
pub(crate) async fn get_recordings(conf_handle: &ConfHandle) -> Result<Json<Vec<String>>, HttpErrorStatus> { | ||
let conf = conf_handle.get_conf(); | ||
let recording_path = conf.recording_path.to_owned(); | ||
let dirs = list_uuid_dirs(recording_path.as_std_path()); | ||
Ok(Json(dirs)) | ||
} |
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