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,4 +1,4 @@ -use actix_web::error::{ErrorBadRequest, ErrorForbidden}; +use actix_web::error::ErrorBadRequest; use actix_web::{web, HttpResponse}; use comm_lib::auth::AuthorizationCredential; use comm_lib::blob::types::http::{ @@ -7,6 +7,7 @@ }; use tracing::{info, instrument, trace, warn}; +use crate::http::utils::verify_caller_is_service; use crate::service::BlobService; #[instrument(name = "assign_multiple_holders", skip_all)] @@ -122,15 +123,3 @@ Ok(()) } - -/// Returns HTTP 403 if caller is not a Comm service -fn verify_caller_is_service( - requesting_identity: &AuthorizationCredential, -) -> actix_web::Result<()> { - match requesting_identity { - AuthorizationCredential::ServicesToken(_) => Ok(()), - _ => Err(ErrorForbidden( - "This endpoint can only be called by other services", - )), - } -} diff --git a/services/blob/src/http/handlers/metadata.rs b/services/blob/src/http/handlers/metadata.rs new file mode 100644 --- /dev/null +++ b/services/blob/src/http/handlers/metadata.rs @@ -0,0 +1,17 @@ +use crate::{http::utils::verify_caller_is_service, service::BlobService}; +use actix_web::{web, HttpResponse}; +use comm_lib::{ + auth::AuthorizationCredential, blob::types::http::BlobSizesRequest, +}; +use tracing::instrument; + +#[instrument(name = "get_blob_sizes", skip_all)] +pub async fn get_blob_sizes( + service: web::Data, + payload: web::Json, + requesting_identity: AuthorizationCredential, +) -> actix_web::Result { + verify_caller_is_service(&requesting_identity)?; + + Ok(HttpResponse::NotImplemented().body("Not implemented yet")) +} 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 @@ -13,6 +13,7 @@ mod handlers { pub(super) mod blob; pub(super) mod holders; + pub(super) mod metadata; } pub async fn run_http_server( @@ -47,10 +48,15 @@ ) .service( web::resource("/holders") - .wrap(auth_middleware) + .wrap(auth_middleware.clone()) .route(web::post().to(handlers::holders::assign_holders_handler)) .route(web::delete().to(handlers::holders::remove_holders_handler)), ) + .service( + web::resource("/metadata/get_blob_sizes") + .wrap(auth_middleware) + .route(web::post().to(handlers::metadata::get_blob_sizes)), + ) }) .bind(("0.0.0.0", CONFIG.http_port))? .run() diff --git a/services/blob/src/http/utils.rs b/services/blob/src/http/utils.rs --- a/services/blob/src/http/utils.rs +++ b/services/blob/src/http/utils.rs @@ -1,3 +1,6 @@ +use actix_web::error::ErrorForbidden; +use comm_lib::auth::AuthorizationCredential; + /// Validates given identifier variable and returns HTTP 400 /// in case of failure #[macro_export] @@ -14,3 +17,15 @@ } }}; } + +/// Returns HTTP 403 if caller is not a Comm service +pub fn verify_caller_is_service( + requesting_identity: &AuthorizationCredential, +) -> actix_web::Result<()> { + match requesting_identity { + AuthorizationCredential::ServicesToken(_) => Ok(()), + _ => Err(ErrorForbidden( + "This endpoint can only be called by other services", + )), + } +} 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 @@ -11,6 +11,8 @@ /// If you edit the definitions in one file, /// please make sure to update the corresponding definitions in the other. pub mod http { + use std::collections::HashMap; + use serde::{Deserialize, Serialize}; pub use super::BlobInfo; @@ -93,6 +95,22 @@ } } } + + // Blob metadata endpoint types + // NOTE: These are accessible from other services and should not be exposed + // to `lib/types/blob-service-types.js` JS definitions. + + #[derive(Serialize, Deserialize, Debug)] + #[serde(rename_all = "camelCase")] + pub struct BlobSizesRequest { + pub blob_hashes: Vec, + } + + #[derive(Serialize, Deserialize, Debug)] + #[serde(rename_all = "camelCase")] + pub struct BlobSizesResponse { + pub blob_sizes: HashMap, + } } /// Blob owning information - stores both blob_hash and holder