Skip to content

Commit 427316d

Browse files
author
Devdutt Shenoi
committed
fix: list all streams when none are provided
1 parent 97f98d4 commit 427316d

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

src/handlers/http/prism_logstream.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717
*/
1818

1919
use actix_web::{
20-
web::{self, Json, Path},
21-
Responder,
20+
web::{self, Json, Path}, HttpRequest, Responder
2221
};
2322

24-
use crate::prism::logstream::{get_prism_logstream_info, PrismDatasetRequest, PrismLogstreamError};
23+
use crate::{prism::logstream::{get_prism_logstream_info, PrismDatasetRequest, PrismLogstreamError}, utils::actix::extract_session_key_from_req};
2524

2625
/// This API is essentially just combining the responses of /info and /schema together
2726
pub async fn get_info(stream_name: Path<String>) -> Result<impl Responder, PrismLogstreamError> {
@@ -31,8 +30,9 @@ pub async fn get_info(stream_name: Path<String>) -> Result<impl Responder, Prism
3130
}
3231

3332
/// A combination of /stats, /retention, /hottier, /info, /counts and /query
34-
pub async fn post_datasets(Json(req): Json<PrismDatasetRequest>) -> Result<impl Responder, PrismLogstreamError> {
35-
let dataset = req.get_datasets().await?;
33+
pub async fn post_datasets(Json(prism_req): Json<PrismDatasetRequest>, req: HttpRequest) -> Result<impl Responder, PrismLogstreamError> {
34+
let session_key = extract_session_key_from_req(&req)?;
35+
let dataset = prism_req.get_datasets(session_key).await?;
3636

3737
Ok(web::Json(dataset))
3838
}

src/prism/logstream/mod.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use chrono::Utc;
2424
use http::StatusCode;
2525
use serde::{Deserialize, Serialize};
2626
use serde_json::{json, Value};
27-
use tracing::debug;
27+
use tracing::{debug, warn};
2828

2929
use crate::{
3030
handlers::http::{
@@ -38,6 +38,7 @@ use crate::{
3838
hottier::{HotTierError, HotTierManager, StreamHotTier},
3939
parseable::{StreamNotFound, PARSEABLE},
4040
query::{error::ExecuteError, execute, CountsRequest, CountsResponse, QUERY_SESSION},
41+
rbac::{map::SessionKey, role::Action, Users},
4142
stats,
4243
storage::{retention::Retention, StreamInfo, StreamType},
4344
utils::{
@@ -237,11 +238,15 @@ impl PrismDatasetRequest {
237238
/// - `Err(PrismLogstreamError)`: If a critical error occurs during processing
238239
///
239240
/// # Note
240-
/// This method won't fail if individual streams fail - it will only include
241+
/// 1. This method won't fail if individual streams fail - it will only include
241242
/// successfully processed streams in the result.
242-
pub async fn get_datasets(self) -> Result<Vec<PrismDatasetResponse>, PrismLogstreamError> {
243+
/// 2. On receiving an empty stream list, we return for all streams the user is able to query for
244+
pub async fn get_datasets(
245+
mut self,
246+
key: SessionKey,
247+
) -> Result<Vec<PrismDatasetResponse>, PrismLogstreamError> {
243248
if self.streams.is_empty() {
244-
return Err(PrismLogstreamError::Empty);
249+
self.streams = PARSEABLE.streams.list();
245250
}
246251

247252
let mut responses = vec![];
@@ -284,7 +289,7 @@ impl PrismDatasetRequest {
284289
fields: vec!["start_time".into(), "end_time".into(), "count".into()],
285290
records,
286291
};
287-
292+
288293
// Retrieve distinct values for source identifiers
289294
// Returns None if fields aren't present or if query fails
290295
let ips = self.get_distinct_entries(&stream, "p_src_ip").await.ok();
@@ -367,8 +372,8 @@ pub enum PrismLogstreamError {
367372
TimeParse(#[from] TimeParseError),
368373
#[error("Execute: {0}")]
369374
Execute(#[from] ExecuteError),
370-
#[error("Empty Stream List")]
371-
Empty,
375+
#[error("Auth: {0}")]
376+
Auth(#[from] actix_web::Error),
372377
}
373378

374379
impl actix_web::ResponseError for PrismLogstreamError {
@@ -381,7 +386,7 @@ impl actix_web::ResponseError for PrismLogstreamError {
381386
PrismLogstreamError::Query(_) => StatusCode::INTERNAL_SERVER_ERROR,
382387
PrismLogstreamError::TimeParse(_) => StatusCode::NOT_FOUND,
383388
PrismLogstreamError::Execute(_) => StatusCode::INTERNAL_SERVER_ERROR,
384-
PrismLogstreamError::Empty => StatusCode::BAD_REQUEST,
389+
PrismLogstreamError::Auth(_) => StatusCode::UNAUTHORIZED,
385390
}
386391
}
387392

0 commit comments

Comments
 (0)