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,8 +1,10 @@ -use actix_web::error::ErrorBadRequest; +use actix_web::error::{ErrorBadRequest, ErrorForbidden}; use actix_web::{web, HttpResponse}; +use comm_lib::auth::AuthorizationCredential; use comm_lib::blob::types::http::{ AssignHoldersRequest, AssignHoldersResponse, BlobInfo, - HolderAssignmentResult, RemoveHoldersRequest, RemoveHoldersResponse, + HolderAssignmentResult, HoldersQueryResponse, HoldersQueryUrlParams, + RemoveHoldersRequest, RemoveHoldersResponse, }; use tracing::{info, instrument, trace, warn}; @@ -101,6 +103,26 @@ Ok(HttpResponse::Ok().json(web::Json(response))) } +#[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)), ) diff --git a/shared/comm-lib/src/blob/types.rs b/shared/comm-lib/src/blob/types.rs --- a/shared/comm-lib/src/blob/types.rs +++ b/shared/comm-lib/src/blob/types.rs @@ -55,6 +55,16 @@ pub failed_requests: Vec, } + // Query holders by prefix + #[derive(Serialize, Deserialize, Debug)] + pub struct HoldersQueryUrlParams { + pub prefix: String, + } + #[derive(Serialize, Deserialize, Debug)] + pub struct HoldersQueryResponse { + pub items: Vec, + } + // Single holder endpoint types #[derive(Serialize, Deserialize, Debug)]