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