diff --git a/services/blob/src/http/handlers/holders.rs b/services/blob/src/http/handlers/holders.rs --- a/services/blob/src/http/handlers/holders.rs +++ b/services/blob/src/http/handlers/holders.rs @@ -1,5 +1,6 @@ -use actix_web::error::ErrorBadRequest; +use actix_web::error::{ErrorBadRequest, ErrorForbidden}; use actix_web::{web, HttpResponse}; +use comm_lib::auth::AuthorizationCredential; use serde::{Deserialize, Serialize}; use tracing::{info, instrument, trace, warn}; @@ -128,6 +129,36 @@ Ok(HttpResponse::Ok().json(web::Json(response))) } +#[derive(Deserialize)] +pub struct HoldersQueryUrlParams { + prefix: String, +} + +#[derive(Serialize)] +pub struct HoldersQueryResponse { + items: Vec, +} + +#[instrument(name = "query_holders", skip_all)] +pub async fn query_holders_handler( + service: web::Data, + query: web::Query, + requesting_identity: AuthorizationCredential, +) -> actix_web::Result { + match requesting_identity { + AuthorizationCredential::ServicesToken(_) => (), + _ => { + return Err(ErrorForbidden( + "This endpoint can only be called by other services", + )); + } + }; + let HoldersQueryUrlParams { prefix } = query.into_inner(); + let items = service.query_indexed_holders(prefix).await?; + let response = HoldersQueryResponse { items }; + Ok(HttpResponse::Ok().json(web::Json(response))) +} + /** * Returns `HTTP 400 Bad Request` if one or more blob hashes or holders * have invalid format. See [`comm_lib::tools::is_valid_identifier`] for diff --git a/services/blob/src/http/mod.rs b/services/blob/src/http/mod.rs --- a/services/blob/src/http/mod.rs +++ b/services/blob/src/http/mod.rs @@ -48,6 +48,7 @@ .service( web::resource("/holders") .wrap(auth_middleware) + .route(web::get().to(handlers::holders::query_holders_handler)) .route(web::post().to(handlers::holders::assign_holders_handler)) .route(web::delete().to(handlers::holders::remove_holders_handler)), )