use tonic::{Request, Response, Status};
use aion_proto::WireError;
use aion_proto::generated;
use super::WorkflowGrpcService;
use super::status::status_from_wire_error;
use crate::namespace::decode_mint_origin;
impl WorkflowGrpcService {
pub(super) async fn mint_namespace_here(
&self,
request: Request<generated::MintNamespaceRequest>,
) -> Result<Response<generated::MintNamespaceResponse>, Status> {
let caller = self.caller(&request).await?;
let inner = request.into_inner();
let origin = decode_mint_origin(inner.origin).ok_or_else(|| {
status_from_wire_error(WireError::invalid_input(
"mint origin is unspecified or unknown",
))
})?;
if inner.namespaces.is_empty() {
return Err(status_from_wire_error(WireError::invalid_input(
"mint request named no namespaces",
)));
}
let namespaces = self
.state
.namespace_guard()
.scope_worker_namespaces(&caller, &inner.namespaces)
.map_err(|error| status_from_wire_error(error.to_wire_error()))?;
self.state
.namespace_minter()
.without_routing()
.mint_or_gate(&namespaces, origin)
.await
.map_err(|error| status_from_wire_error(error.to_wire_error()))?;
Ok(Response::new(generated::MintNamespaceResponse {}))
}
}