manta_server/server/handlers/
ephemeral_env.rs1use axum::{Json, http::StatusCode, response::IntoResponse};
4use serde::Deserialize;
5use utoipa::ToSchema;
6
7use super::{ErrorResponse, RequestCtx, SiteHeader, to_handler_error};
8
9#[derive(Deserialize, ToSchema)]
15pub struct CreateEphemeralEnvRequest {
16 pub image_id: String,
18}
19
20#[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}