manta_server/server/handlers/
ephemeral_env.rs

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