manta_server/server/handlers/
ephemeral_env.rs

1//! Ephemeral environment handler.
2//!
3//! `POST /api/v1/ephemeral-env` → [`create_ephemeral_env`] — wraps
4//! `service::ephemeral_env::exec`. Launches a short-lived CFS
5//! environment booted from a caller-supplied IMS image and returns
6//! the hostname the user can attach to via the console endpoint.
7
8use axum::{Json, http::StatusCode, response::IntoResponse};
9use serde::Deserialize;
10use utoipa::ToSchema;
11
12use super::{ErrorResponse, RequestCtx, SiteHeader, to_handler_error};
13
14// ---------------------------------------------------------------------------
15// POST /api/v1/ephemeral-env — Create ephemeral CFS environment
16// ---------------------------------------------------------------------------
17
18/// Request body for `POST /ephemeral-env`.
19#[derive(Deserialize, ToSchema)]
20pub struct CreateEphemeralEnvRequest {
21  /// IMS image ID to boot the ephemeral environment from.
22  pub image_id: String,
23}
24
25/// `POST /api/v1/ephemeral-env` — launch an ephemeral CFS environment from an IMS image.
26#[utoipa::path(post, path = "/ephemeral-env", tag = "ephemeral-env",
27  params(SiteHeader),
28  request_body = CreateEphemeralEnvRequest,
29  security(("bearerAuth" = [])),
30  responses(
31    (status = 201, description = "Ephemeral env created", body = manta_shared::types::api::responses::EphemeralEnvResponse),
32    (status = 401, description = "Unauthorized",          body = ErrorResponse),
33    (status = 500, description = "Internal error",        body = ErrorResponse),
34  )
35)]
36#[tracing::instrument(skip_all)]
37pub async fn create_ephemeral_env(
38  ctx: RequestCtx,
39  Json(body): Json<CreateEphemeralEnvRequest>,
40) -> Result<impl IntoResponse, (StatusCode, Json<ErrorResponse>)> {
41  tracing::info!("create_ephemeral_env image_id={}", body.image_id);
42  let infra = ctx.infra();
43
44  let hostname =
45    crate::service::ephemeral_env::exec(&infra, &ctx.token, &body.image_id)
46      .await
47      .map_err(to_handler_error)?;
48
49  Ok((
50    StatusCode::CREATED,
51    Json(serde_json::json!({ "hostname": hostname })),
52  ))
53}