manta_shared/types/api/sat_file.rs
1//! HTTP request/response bodies for the per-element SAT-file apply
2//! endpoints under `POST /v2/sat-file/*`, plus CLI-built params
3//! for the backend's whole-file `apply_sat_file` pass-through.
4
5use std::collections::HashMap;
6
7use serde::{Deserialize, Serialize};
8use utoipa::ToSchema;
9
10use crate::types::dto::BosSessionTemplate;
11use manta_backend_dispatcher::types::bos::session::BosSession;
12
13/// Request body for `POST /v2/sat-file/configurations`.
14///
15/// Carries one entry from the SAT file's `configurations` section
16/// plus per-call flags. csm-rs owns the SAT schema; the CLI and server
17/// just shuttle the entry through as `serde_json::Value`.
18#[derive(Debug, Serialize, Deserialize, ToSchema)]
19pub struct PostSatConfigurationRequest {
20 /// One SAT `configurations[]` entry as a structured value.
21 #[schema(value_type = serde_json::Value)]
22 pub configuration: serde_json::Value,
23 /// Overwrite an existing CFS configuration of the same name.
24 #[serde(default)]
25 pub overwrite: bool,
26 /// Validate without creating; the response contains a mock
27 /// configuration.
28 #[serde(default)]
29 pub dry_run: bool,
30}
31
32/// Request body for `POST /v2/sat-file/images/cfs-session`.
33///
34/// Carries one entry from the SAT file's `images` section plus the
35/// CLI's accumulated `ref_lookup` and the ansible knobs the CFS
36/// session needs.
37#[derive(Debug, Serialize, Deserialize, ToSchema)]
38pub struct CreateImageCfsSessionRequest {
39 /// One SAT `images[]` entry as a structured value.
40 #[schema(value_type = serde_json::Value)]
41 pub image: serde_json::Value,
42 /// `ref_name.or(name) -> image_id` map for previously-created
43 /// images. The backend uses it to resolve `base.image_ref` chains.
44 #[serde(default)]
45 pub ref_lookup: HashMap<String, String>,
46 /// Ansible verbosity level (0–4) for the CFS session that builds
47 /// the image.
48 pub ansible_verbosity: Option<u8>,
49 /// Extra arguments forwarded verbatim to `ansible-playbook`.
50 pub ansible_passthrough: Option<String>,
51 /// Validate without creating; the server returns a mocked complete
52 /// session with a `DRYRUN-<uuid>` result id.
53 #[serde(default)]
54 pub dry_run: bool,
55}
56
57/// Request body for `POST /v2/sat-file/images/stamp`.
58#[derive(Debug, Serialize, Deserialize, ToSchema)]
59pub struct StampImageFromSessionRequest {
60 /// Name of the (already terminal-complete) CFS session whose result
61 /// image should be stamped with `manta.image_session.*` provenance.
62 pub cfs_session_name: String,
63}
64
65/// Request body for `POST /v2/sat-file/session-templates`.
66///
67/// Carries one entry from the SAT file's `session_templates` section
68/// plus the CLI's accumulated `ref_lookup` and per-call flags.
69#[derive(Debug, Serialize, Deserialize, ToSchema)]
70pub struct PostSatSessionTemplateRequest {
71 /// One SAT `session_templates[]` entry as a structured value.
72 #[schema(value_type = serde_json::Value)]
73 pub session_template: serde_json::Value,
74 /// `ref_name.or(name) -> image_id` map for previously-created
75 /// images; the backend uses it to resolve `image.image_ref`.
76 #[serde(default)]
77 pub ref_lookup: HashMap<String, String>,
78 /// After creating the template, create a BOS session from it so its
79 /// target nodes boot via the new template (typically a reboot).
80 #[serde(default)]
81 pub create_bos_session: bool,
82 /// Validate without creating; the response contains a mock template,
83 /// and if `create_bos_session` was set the response also contains a
84 /// mock BOS session (no status, name prefixed with `dry-run-`) so the
85 /// client can preview the session that would have been created.
86 #[serde(default)]
87 pub dry_run: bool,
88}
89
90/// Response body for `POST /v2/sat-file/session-templates`.
91///
92/// `session` is populated when `create_bos_session` was true. In a real
93/// apply it carries the freshly-created BOS session; in a dry-run it
94/// carries a mock with no status and a `dry-run-` name prefix.
95#[derive(Debug, Serialize, Deserialize, ToSchema)]
96pub struct PostSatSessionTemplateResponse {
97 /// The created (or mock, in dry-run) BOS session template.
98 #[schema(value_type = serde_json::Value)]
99 pub template: BosSessionTemplate,
100 /// The BOS session created from the new template, if any.
101 #[schema(value_type = Option<serde_json::Value>)]
102 pub session: Option<BosSession>,
103}
104
105/// Parameters for applying a SAT file via the whole-file backend
106/// pathway.
107///
108/// The CLI renders Jinja2, parses the rendered YAML into a structured
109/// value, applies the `image_only` / `session_template_only` filters
110/// client-side (by removing top-level keys), and forwards the resulting
111/// `serde_json::Value` plus the apply-time flags through the server to
112/// the backend.
113pub struct ApplySatFileParams<'a> {
114 /// SAT file parsed into a structured value — Jinja2 already
115 /// evaluated and `image_only` / `session_template_only` filters
116 /// already applied client-side.
117 pub sat_file: serde_json::Value,
118 /// Ansible verbosity level (0–4) passed to any CFS sessions
119 /// created by this SAT file.
120 pub ansible_verbosity: Option<u8>,
121 /// Extra arguments forwarded verbatim to `ansible-playbook`.
122 pub ansible_passthrough: Option<&'a str>,
123 /// When true, after each new BOS session template is created,
124 /// create a BOS session from it so the targeted nodes boot via the
125 /// new template (typically a reboot).
126 pub create_bos_session: bool,
127 /// When true, stream CFS session logs to the caller as part of
128 /// the response.
129 pub watch_logs: bool,
130 /// When true, prefix each streamed log line with its timestamp.
131 pub timestamps: bool,
132 /// Overwrite existing CFS configurations or IMS images instead
133 /// of erroring on conflict.
134 pub overwrite: bool,
135 /// Render and validate the SAT file without creating any
136 /// resources.
137 pub dry_run: bool,
138}