move the /logs route to the /logs/stream route

This commit is contained in:
Tamo 2024-02-07 12:13:57 +01:00
parent 4f9539d91e
commit f839c8e61d
4 changed files with 19 additions and 19 deletions

View File

@ -26,7 +26,7 @@ use crate::LogRouteHandle;
pub fn configure(cfg: &mut web::ServiceConfig) { pub fn configure(cfg: &mut web::ServiceConfig) {
cfg.service( cfg.service(
web::resource("") web::resource("stream")
.route(web::post().to(SeqHandler(get_logs))) .route(web::post().to(SeqHandler(get_logs)))
.route(web::delete().to(SeqHandler(cancel_logs))), .route(web::delete().to(SeqHandler(cancel_logs))),
); );

View File

@ -59,8 +59,8 @@ pub static AUTHORIZATIONS: Lazy<HashMap<(&'static str, &'static str), HashSet<&'
("POST", "/snapshots") => hashset!{"snapshots.create", "snapshots.*", "*"}, ("POST", "/snapshots") => hashset!{"snapshots.create", "snapshots.*", "*"},
("GET", "/version") => hashset!{"version", "*"}, ("GET", "/version") => hashset!{"version", "*"},
("GET", "/metrics") => hashset!{"metrics.get", "metrics.*", "*"}, ("GET", "/metrics") => hashset!{"metrics.get", "metrics.*", "*"},
("POST", "/logs") => hashset!{"metrics.get", "metrics.*", "*"}, ("POST", "/logs/stream") => hashset!{"metrics.get", "metrics.*", "*"},
("DELETE", "/logs") => hashset!{"metrics.get", "metrics.*", "*"}, ("DELETE", "/logs/stream") => hashset!{"metrics.get", "metrics.*", "*"},
("PATCH", "/keys/mykey/") => hashset!{"keys.update", "*"}, ("PATCH", "/keys/mykey/") => hashset!{"keys.update", "*"},
("GET", "/keys/mykey/") => hashset!{"keys.get", "*"}, ("GET", "/keys/mykey/") => hashset!{"keys.get", "*"},
("DELETE", "/keys/mykey/") => hashset!{"keys.delete", "*"}, ("DELETE", "/keys/mykey/") => hashset!{"keys.delete", "*"},

View File

@ -4,11 +4,11 @@ use crate::common::Server;
use crate::json; use crate::json;
#[actix_rt::test] #[actix_rt::test]
async fn logs_bad_target() { async fn logs_stream_bad_target() {
let server = Server::new().await; let server = Server::new().await;
// Wrong type // Wrong type
let (response, code) = server.service.post("/logs", json!({ "target": true })).await; let (response, code) = server.service.post("/logs/stream", json!({ "target": true })).await;
snapshot!(code, @"400 Bad Request"); snapshot!(code, @"400 Bad Request");
snapshot!(response, @r###" snapshot!(response, @r###"
{ {
@ -20,7 +20,7 @@ async fn logs_bad_target() {
"###); "###);
// Wrong type // Wrong type
let (response, code) = server.service.post("/logs", json!({ "target": [] })).await; let (response, code) = server.service.post("/logs/stream", json!({ "target": [] })).await;
snapshot!(code, @"400 Bad Request"); snapshot!(code, @"400 Bad Request");
snapshot!(response, @r###" snapshot!(response, @r###"
{ {
@ -32,7 +32,7 @@ async fn logs_bad_target() {
"###); "###);
// Our help message // Our help message
let (response, code) = server.service.post("/logs", json!({ "target": "" })).await; let (response, code) = server.service.post("/logs/stream", json!({ "target": "" })).await;
snapshot!(code, @"400 Bad Request"); snapshot!(code, @"400 Bad Request");
snapshot!(response, @r###" snapshot!(response, @r###"
{ {
@ -44,7 +44,7 @@ async fn logs_bad_target() {
"###); "###);
// An error from the target parser // An error from the target parser
let (response, code) = server.service.post("/logs", json!({ "target": "==" })).await; let (response, code) = server.service.post("/logs/stream", json!({ "target": "==" })).await;
snapshot!(code, @"400 Bad Request"); snapshot!(code, @"400 Bad Request");
snapshot!(response, @r###" snapshot!(response, @r###"
{ {
@ -57,11 +57,11 @@ async fn logs_bad_target() {
} }
#[actix_rt::test] #[actix_rt::test]
async fn logs_bad_mode() { async fn logs_stream_bad_mode() {
let server = Server::new().await; let server = Server::new().await;
// Wrong type // Wrong type
let (response, code) = server.service.post("/logs", json!({ "mode": true })).await; let (response, code) = server.service.post("/logs/stream", json!({ "mode": true })).await;
snapshot!(code, @"400 Bad Request"); snapshot!(code, @"400 Bad Request");
snapshot!(response, @r###" snapshot!(response, @r###"
{ {
@ -73,7 +73,7 @@ async fn logs_bad_mode() {
"###); "###);
// Wrong type // Wrong type
let (response, code) = server.service.post("/logs", json!({ "mode": [] })).await; let (response, code) = server.service.post("/logs/stream", json!({ "mode": [] })).await;
snapshot!(code, @"400 Bad Request"); snapshot!(code, @"400 Bad Request");
snapshot!(response, @r###" snapshot!(response, @r###"
{ {
@ -85,7 +85,7 @@ async fn logs_bad_mode() {
"###); "###);
// Wrong value // Wrong value
let (response, code) = server.service.post("/logs", json!({ "mode": "tamo" })).await; let (response, code) = server.service.post("/logs/stream", json!({ "mode": "tamo" })).await;
snapshot!(code, @"400 Bad Request"); snapshot!(code, @"400 Bad Request");
snapshot!(response, @r###" snapshot!(response, @r###"
{ {
@ -98,10 +98,10 @@ async fn logs_bad_mode() {
} }
#[actix_rt::test] #[actix_rt::test]
async fn logs_without_enabling_the_route() { async fn logs_stream_without_enabling_the_route() {
let server = Server::new().await; let server = Server::new().await;
let (response, code) = server.service.post("/logs", json!({})).await; let (response, code) = server.service.post("/logs/stream", json!({})).await;
snapshot!(code, @"400 Bad Request"); snapshot!(code, @"400 Bad Request");
snapshot!(response, @r###" snapshot!(response, @r###"
{ {
@ -112,7 +112,7 @@ async fn logs_without_enabling_the_route() {
} }
"###); "###);
let (response, code) = server.service.delete("/logs").await; let (response, code) = server.service.delete("/logs/stream").await;
snapshot!(code, @"400 Bad Request"); snapshot!(code, @"400 Bad Request");
snapshot!(response, @r###" snapshot!(response, @r###"
{ {

View File

@ -14,7 +14,7 @@ use crate::common::{default_settings, Server};
use crate::json; use crate::json;
#[actix_web::test] #[actix_web::test]
async fn basic_test_log_route() { async fn basic_test_log_stream_route() {
let db_path = tempfile::tempdir().unwrap(); let db_path = tempfile::tempdir().unwrap();
let server = Server::new_with_options(Opt { let server = Server::new_with_options(Opt {
experimental_enable_logs_route: true, experimental_enable_logs_route: true,
@ -50,11 +50,11 @@ async fn basic_test_log_route() {
let app = Rc::new(app); let app = Rc::new(app);
// First, we start listening on the `/logs` route // First, we start listening on the `/logs/stream` route
let handle_app = app.clone(); let handle_app = app.clone();
let handle = tokio::task::spawn_local(async move { let handle = tokio::task::spawn_local(async move {
let req = actix_web::test::TestRequest::post() let req = actix_web::test::TestRequest::post()
.uri("/logs") .uri("/logs/stream")
.insert_header(ContentType::json()) .insert_header(ContentType::json())
.set_payload( .set_payload(
serde_json::to_vec(&json!({ serde_json::to_vec(&json!({
@ -81,7 +81,7 @@ async fn basic_test_log_route() {
"###); "###);
server.wait_task(ret.uid()).await; server.wait_task(ret.uid()).await;
let req = actix_web::test::TestRequest::delete().uri("/logs"); let req = actix_web::test::TestRequest::delete().uri("/logs/stream");
let req = req.to_request(); let req = req.to_request();
let ret = actix_web::test::call_service(&*app, req).await; let ret = actix_web::test::call_service(&*app, req).await;
let code = ret.status(); let code = ret.status();