manta_server/server/handlers/
ephemeral_env.rs1use axum::{Json, http::StatusCode, response::IntoResponse};
9use serde::Deserialize;
10use utoipa::ToSchema;
11
12use super::{ErrorResponse, RequestCtx, SiteHeader, to_handler_error};
13
14#[derive(Deserialize, ToSchema)]
20pub struct CreateEphemeralEnvRequest {
21 pub image_id: String,
23}
24
25#[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}