Skip to content
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

Add an endpoint to clear an instance's console buffer #408

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions core/src/handlers/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,37 @@
}
}

pub async fn clear_console_buffer(
axum::extract::State(state): axum::extract::State<AppState>,
AuthBearer(token): AuthBearer,
Path(uuid): Path<InstanceUuid>,
) -> Result<Json<()>, Error> {
let requester = state
.users_manager
.read()
.await
.try_auth(&token)
.ok_or_else(|| Error {
kind: ErrorKind::Unauthorized,
source: eyre!("Token error"),
})?;
if !requester.can_perform_action(&UserAction::ClearConsoleBuffer(uuid.clone())) {

Check failure on line 304 in core/src/handlers/events.rs

View workflow job for this annotation

GitHub Actions / clippy

failed to resolve: use of undeclared type `UserAction`

error[E0433]: failed to resolve: use of undeclared type `UserAction` --> core/src/handlers/events.rs:304:39 | 304 | if !requester.can_perform_action(&UserAction::ClearConsoleBuffer(uuid.clone())) { | ^^^^^^^^^^ use of undeclared type `UserAction` | help: consider importing this enum | 1 + use crate::auth::user::UserAction; |
return Err(Error {
kind: ErrorKind::PermissionDenied,
source: eyre!("You don't have permission to clear the console buffer"),
});
}
state.clear_console_buffer(&uuid).await;
Ok(Json(()))
}

pub fn get_events_routes(state: AppState) -> Router {
Router::new()
.route("/events/:uuid/stream", get(event_stream))
.route("/events/:uuid/buffer", get(get_event_buffer))
.route("/events/search", get(get_event_search))
.route("/instance/:uuid/console/stream", get(console_stream))
.route("/instance/:uuid/console/buffer", get(get_console_buffer))
.route("/instance/:uuid/console/clear", get(clear_console_buffer))
.with_state(state)
}
4 changes: 4 additions & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ impl AppState {
});
}
}

pub async fn clear_console_buffer(&self, uuid: &InstanceUuid) {
self.console_out_buffer.lock().await.remove(uuid);
}
}

async fn restore_instances(
Expand Down
Loading