Skip to main content

stormchaser_model/dsl/
specs.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3use serde_json::Value;
4use std::collections::HashMap;
5
6use super::{Input, StorageMount};
7
8/// Minimal common set of arguments for running containers (portable across runners)
9#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
10pub struct CommonContainerSpec {
11    /// Container image to run.
12    pub image: String,
13    /// Override the container entrypoint.
14    pub command: Option<Vec<String>>,
15    /// Arguments passed to the command.
16    pub args: Option<Vec<String>>,
17    /// Environment variables.
18    pub env: Option<Vec<EnvVar>>,
19    /// Requested CPU.
20    pub cpu: Option<String>,
21    /// Requested memory.
22    pub memory: Option<String>,
23    /// Whether to run in privileged mode.
24    pub privileged: Option<bool>,
25    /// Storage volumes to mount.
26    pub storage_mounts: Option<Vec<StorageMount>>,
27}
28
29/// Structured specification for a Kubernetes Job (RunK8sJob step)
30#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
31pub struct K8sJobSpec {
32    /// Container image.
33    pub image: String,
34    /// Command.
35    pub command: Option<Vec<String>>,
36    /// Arguments.
37    pub args: Option<Vec<String>>,
38    /// Environment variables.
39    pub env: Option<Vec<EnvVar>>,
40    /// Resource requirements.
41    pub resources: Option<Resources>,
42    /// Secret mounts.
43    pub secret_mounts: Option<Vec<SecretMount>>,
44    /// Config map mounts.
45    pub config_map_mounts: Option<Vec<ConfigMapMount>>,
46    /// Storage mounts.
47    pub storage_mounts: Option<Vec<StorageMount>>,
48
49    /// Active deadline seconds.
50    pub active_deadline_seconds: Option<i64>,
51    /// Backoff limit.
52    pub backoff_limit: Option<i32>,
53    /// Completions.
54    pub completions: Option<i32>,
55    /// Parallelism.
56    pub parallelism: Option<i32>,
57    /// TTL seconds after finished.
58    pub ttl_seconds_after_finished: Option<i32>,
59    /// Privileged flag.
60    pub privileged: Option<bool>,
61    /// Minimum version of K8s node.
62    pub minimum_version: Option<String>,
63    /// Node selector labels.
64    pub node_selector: Option<HashMap<String, String>>,
65    /// Service account name.
66    pub service_account_name: Option<String>,
67    /// Restart policy.
68    pub restart_policy: Option<String>, // "OnFailure" or "Never"
69    /// Custom labels.
70    pub labels: Option<HashMap<String, String>>,
71    /// Custom annotations.
72    pub annotations: Option<HashMap<String, String>>,
73}
74
75/// Key-value pair for environment variables.
76#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
77pub struct EnvVar {
78    /// Variable name.
79    pub name: String,
80    /// Variable value.
81    pub value: String,
82}
83
84/// Resource specification for CPU and memory.
85#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
86pub struct Resources {
87    /// Minimum guaranteed resources.
88    pub requests: Option<ResourceRequirements>,
89    /// Maximum allowed resources.
90    pub limits: Option<ResourceRequirements>,
91}
92
93/// Resource requirements structure.
94#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
95pub struct ResourceRequirements {
96    /// CPU specification.
97    pub cpu: Option<String>,
98    /// Memory specification.
99    pub memory: Option<String>,
100}
101
102/// Secret mount definition.
103#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
104pub struct SecretMount {
105    /// Name of the secret.
106    pub name: String,
107    /// Mount path.
108    pub mount_path: String,
109}
110
111/// ConfigMap mount definition.
112#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
113pub struct ConfigMapMount {
114    /// Name of the ConfigMap.
115    pub name: String,
116    /// Mount path.
117    pub mount_path: String,
118}
119
120/// Human-in-the-loop approval specification.
121#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
122pub struct ApprovalSpec {
123    /// List of user IDs or groups allowed to approve.
124    pub approvers: Option<Vec<String>>,
125    /// Input fields required during approval.
126    pub inputs: Option<Vec<Input>>,
127    /// Notification settings.
128    pub notify: Option<EmailSpec>,
129    /// Timeout for waiting for approval.
130    pub timeout: Option<String>,
131}
132
133/// Specification for waiting on a system event.
134#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
135pub struct WaitEventSpec {
136    /// Key used for correlation.
137    pub correlation_key: String,
138    /// Expected value for correlation.
139    pub correlation_value: String,
140    /// Timeout.
141    pub timeout: Option<String>,
142}
143
144/// Specification for invoking an AWS Lambda function.
145#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
146pub struct LambdaInvokeSpec {
147    /// Name of the Lambda function.
148    pub function_name: String,
149    /// JSON payload.
150    pub payload: Option<Value>,
151    /// Invocation type.
152    pub invocation_type: Option<String>, // "RequestResponse", "Event", "DryRun"
153    /// Qualifier (alias/version).
154    pub qualifier: Option<String>, // Alias or version
155    /// AWS Region.
156    pub region: Option<String>,
157    /// IAM Role ARN to assume.
158    pub assume_role_arn: Option<String>, // IAM Role ARN to assume
159    /// Optional session name.
160    pub role_session_name: Option<String>, // Optional session name for the assumed role
161}
162
163/// Specification for checking out a Git repository.
164#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
165pub struct GitCheckoutSpec {
166    /// Repository URL.
167    pub repo: String,
168    /// Git reference (branch, tag, commit).
169    pub r#ref: Option<String>,
170    /// Clone depth.
171    pub depth: Option<u32>,
172    /// Sparse checkout paths.
173    pub sparse_checkout: Option<Vec<String>>,
174    /// Destination directory.
175    pub destination: Option<String>,
176    /// Storage mounts.
177    pub storage_mounts: Option<Vec<StorageMount>>,
178}
179
180/// Specification for executing a WASM module.
181#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
182pub struct WasmStepSpec {
183    /// URI to WASM module.
184    pub module: String, // URI to WASM module (e.g., file://, s3://, or registry name)
185    /// Function to invoke.
186    pub function: String,
187    /// Arguments to pass.
188    pub args: Option<Value>,
189}
190
191/// Specification for invoking a Webhook.
192#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
193pub struct WebhookInvokeSpec {
194    /// Webhook URL.
195    pub url: String,
196    /// HTTP method.
197    pub method: Option<String>, // Default to POST
198    /// HTTP headers.
199    pub headers: Option<HashMap<String, String>>,
200    /// Request body template.
201    pub body: Option<String>, // MiniJinja template
202    /// Request timeout.
203    pub timeout: Option<String>,
204}
205
206/// Supported email backends.
207#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
208#[serde(rename_all = "snake_case")]
209pub enum EmailBackend {
210    /// Standard SMTP protocol.
211    Smtp,
212    /// Amazon Simple Email Service.
213    Ses,
214}
215
216/// Specification for sending an email notification.
217#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
218pub struct EmailSpec {
219    /// Sender address.
220    pub from: String,
221    /// List of recipient addresses.
222    pub to: Vec<String>,
223    /// CC addresses.
224    pub cc: Option<Vec<String>>,
225    /// BCC addresses.
226    pub bcc: Option<Vec<String>>,
227    /// Email subject.
228    pub subject: String,
229    /// Body template (MiniJinja).
230    pub body: String, // MiniJinja template
231    /// Send as HTML.
232    pub html: Option<bool>,
233    /// Email backend choice.
234    pub backend: Option<EmailBackend>, // Defaults to SMTP
235    /// SMTP Server address.
236    pub smtp_server: Option<String>,
237    /// SMTP Port.
238    pub smtp_port: Option<u16>,
239    /// SMTP username.
240    pub smtp_username: Option<String>,
241    /// SMTP password.
242    pub smtp_password: Option<String>,
243    /// Use TLS.
244    pub smtp_use_tls: Option<bool>,
245    /// Use mTLS.
246    pub smtp_use_mtls: Option<bool>,
247    /// SES region.
248    pub ses_region: Option<String>,
249    /// SES role ARN to assume.
250    pub ses_role_arn: Option<String>,
251    /// SES configuration set.
252    pub ses_configuration_set_name: Option<String>,
253}
254
255/// Specification for rendering a Jinja template.
256#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
257pub struct JinjaRenderSpec {
258    /// The template string.
259    pub template: String,
260    /// Context variables for rendering.
261    pub context: Option<Value>,
262    /// Output key for the result.
263    pub output_key: Option<String>, // Key to store the result in step outputs, defaults to "result"
264}
265
266/// Specification for emailing a test report.
267#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
268pub struct TestReportEmailSpec {
269    /// Sender address.
270    pub from: String,
271    /// Recipient addresses.
272    pub to: Vec<String>,
273    /// Email subject.
274    pub subject: String,
275    /// Custom template to override default.
276    pub template: Option<String>, // Override default template
277    /// Specific report name to send, or all if None.
278    pub report_name: Option<String>, // If None, send all reports for the run
279    /// Backend to use.
280    pub backend: Option<EmailBackend>, // Defaults to SMTP
281    /// SMTP Server.
282    pub smtp_server: Option<String>,
283    /// SMTP Port.
284    pub smtp_port: Option<u16>,
285    /// SMTP username.
286    pub smtp_username: Option<String>,
287    /// SMTP password.
288    pub smtp_password: Option<String>,
289    /// Use TLS.
290    pub smtp_use_tls: Option<bool>,
291    /// Use mTLS.
292    pub smtp_use_mtls: Option<bool>,
293    /// SES region.
294    pub ses_region: Option<String>,
295    /// SES role ARN.
296    pub ses_role_arn: Option<String>,
297    /// SES config set.
298    pub ses_configuration_set_name: Option<String>,
299}
300
301/// Specification for running a JQ query on data.
302#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
303pub struct JqSpec {
304    /// JQ program string.
305    pub program: String,
306    /// JSON input data.
307    pub input: Option<Value>,
308    /// Input file path.
309    pub input_file: Option<String>,
310    /// Output file path.
311    pub output_file: Option<String>,
312    /// Storage mounts.
313    pub storage_mounts: Option<Vec<StorageMount>>,
314}