Skip to main content

stormchaser_api/routes/
mod.rs

1use serde_json::Value;
2use std::collections::HashMap;
3use stormchaser_model::workflow::RunStatus;
4/// Module for auth.
5pub mod auth;
6/// Module for cron.
7pub mod cron;
8/// Module for event rule.
9pub mod event_rule;
10/// Module for MCP (Model Context Protocol).
11#[cfg(feature = "mcp")]
12pub mod mcp;
13/// Module for schema.
14pub mod schema;
15/// Module for step.
16pub mod step;
17/// Module for storage.
18pub mod storage;
19/// Module for webhook.
20pub mod webhook;
21/// Module for workflow.
22pub mod workflow;
23
24use chrono::{DateTime, Utc};
25use serde::{Deserialize, Serialize};
26use utoipa::{IntoParams, ToSchema};
27
28use stormchaser_model::step::{StepInstance, StepOutput, StepStatusHistory};
29use stormchaser_model::storage::{ArtifactRegistry, BackendType};
30use stormchaser_model::test_report;
31
32#[derive(Debug, Deserialize, ToSchema)]
33/// Authexchangerequest.
34pub struct AuthExchangeRequest {
35    /// The sso token.
36    pub sso_token: String,
37    /// The callback url.
38    pub callback_url: String,
39}
40
41#[derive(Debug, Serialize, Deserialize, ToSchema)]
42/// Authexchangeresponse.
43pub struct AuthExchangeResponse {
44    /// The access token.
45    pub access_token: String,
46    /// The refresh token.
47    pub refresh_token: Option<String>,
48    /// The token type.
49    pub token_type: String,
50    /// The expires in.
51    pub expires_in: usize,
52}
53
54#[derive(Debug, Deserialize, ToSchema)]
55/// Authrefreshrequest.
56pub struct AuthRefreshRequest {
57    /// The refresh token.
58    pub refresh_token: String,
59}
60
61#[derive(Debug, Deserialize, ToSchema)]
62/// Enqueuerequest.
63pub struct EnqueueRequest {
64    /// The workflow name.
65    pub workflow_name: String,
66    /// The repo url.
67    pub repo_url: String,
68    /// The workflow path.
69    pub workflow_path: String,
70    /// The git ref.
71    pub git_ref: String,
72    /// The inputs.
73    #[schema(value_type = Object)]
74    pub inputs: Value,
75    /// The overrides.
76    pub overrides: Option<RunOverrides>,
77}
78
79#[derive(Debug, Deserialize, ToSchema)]
80/// Runoverrides.
81pub struct RunOverrides {
82    /// The timeout.
83    pub timeout: Option<String>,
84}
85
86#[derive(Debug, Serialize, Deserialize, ToSchema)]
87/// Enqueueresponse.
88pub struct EnqueueResponse {
89    /// The run id.
90    pub run_id: stormchaser_model::RunId,
91    /// The status.
92    pub status: RunStatus,
93}
94
95#[derive(Debug, Deserialize, ToSchema, IntoParams)]
96#[into_params(parameter_in = Query)]
97/// Listrunsquery.
98pub struct ListRunsQuery {
99    /// The workflow name.
100    pub workflow_name: Option<String>,
101    #[schema(value_type = Option<String>)]
102    #[param(value_type = Option<String>)]
103    /// The status.
104    pub status: Option<RunStatus>,
105    /// The initiating user.
106    pub initiating_user: Option<String>,
107    /// The repo url.
108    pub repo_url: Option<String>,
109    /// The workflow path.
110    pub workflow_path: Option<String>,
111    /// The created after.
112    pub created_after: Option<DateTime<Utc>>,
113    /// The created before.
114    pub created_before: Option<DateTime<Utc>>,
115    /// The limit.
116    pub limit: Option<usize>,
117    /// The offset.
118    pub offset: Option<usize>,
119}
120
121#[derive(Debug, Serialize, Deserialize, ToSchema, sqlx::FromRow)]
122/// Workflowrundetail.
123pub struct WorkflowRunDetail {
124    /// The id.
125    pub id: stormchaser_model::RunId,
126    /// The workflow name.
127    pub workflow_name: String,
128    /// The initiating user.
129    pub initiating_user: String,
130    /// The repo url.
131    pub repo_url: String,
132    /// The workflow path.
133    pub workflow_path: String,
134    /// The git ref.
135    pub git_ref: String,
136    /// The status.
137    pub status: RunStatus,
138    /// The version.
139    pub version: i32,
140    /// The created at.
141    pub created_at: DateTime<Utc>,
142    /// The updated at.
143    pub updated_at: DateTime<Utc>,
144    /// The started resolving at.
145    pub started_resolving_at: Option<DateTime<Utc>>,
146    /// The started at.
147    pub started_at: Option<DateTime<Utc>>,
148    /// The finished at.
149    pub finished_at: Option<DateTime<Utc>>,
150    /// The error.
151    pub error: Option<String>,
152    /// The inputs.
153    #[schema(value_type = Object)]
154    pub inputs: Value,
155    /// The secrets.
156    pub secrets: Value,
157    /// The source code.
158    pub source_code: String,
159    /// The dsl version.
160    pub dsl_version: String,
161}
162
163#[derive(Debug, Serialize, Deserialize, ToSchema)]
164/// Workflowrunfulldetail.
165pub struct WorkflowRunFullDetail {
166    /// The detail.
167    pub detail: WorkflowRunDetail,
168    /// The steps.
169    pub steps: Vec<StepDetail>,
170    #[schema(value_type = Vec<Object>)]
171    /// The artifacts.
172    pub artifacts: Vec<ArtifactRegistry>,
173    /// The test summaries.
174    pub test_summaries: Vec<TestSummaryResponse>,
175    #[schema(value_type = Vec<Object>)]
176    /// The test cases.
177    pub test_cases: Vec<test_report::TestCase>,
178}
179
180#[derive(Debug, Serialize, Deserialize, ToSchema)]
181/// Stepdetail.
182pub struct StepDetail {
183    /// The instance.
184    pub instance: StepInstance,
185    /// The outputs.
186    pub outputs: Vec<StepOutput>,
187    /// The history.
188    pub history: Vec<StepStatusHistory>,
189    /// The logs.
190    pub logs: Vec<String>,
191}
192
193#[derive(Debug, Deserialize, ToSchema)]
194/// Directrunrequest.
195pub struct DirectRunRequest {
196    /// The dsl.
197    pub dsl: String,
198    /// The inputs.
199    #[schema(value_type = Object)]
200    pub inputs: Value,
201}
202
203#[derive(Debug, Deserialize, ToSchema)]
204/// Createwebhookrequest.
205pub struct CreateWebhookRequest {
206    /// The name.
207    pub name: String,
208    /// The description.
209    pub description: Option<String>,
210    /// The source type.
211    pub source_type: String, // e.g. "github", "generic"
212    /// The secret token.
213    pub secret_token: Option<String>,
214}
215
216#[derive(Debug, Deserialize, ToSchema)]
217/// Updatewebhookrequest.
218pub struct UpdateWebhookRequest {
219    /// The name.
220    pub name: Option<String>,
221    /// The description.
222    pub description: Option<String>,
223    /// The source type.
224    pub source_type: Option<String>, // e.g. "github", "generic"
225    /// The secret token.
226    pub secret_token: Option<String>,
227    /// Is active.
228    pub is_active: Option<bool>,
229}
230
231#[derive(Debug, Deserialize, ToSchema)]
232/// Createeventrulerequest.
233pub struct CreateEventRuleRequest {
234    /// The name.
235    pub name: String,
236    /// The description.
237    pub description: Option<String>,
238    /// The webhook id.
239    pub webhook_id: stormchaser_model::WebhookId,
240    /// The event type pattern.
241    pub event_type_pattern: String,
242    /// The condition expr.
243    pub condition_expr: Option<String>,
244    /// The workflow name.
245    pub workflow_name: String,
246    /// The repo url.
247    pub repo_url: String,
248    /// The workflow path.
249    pub workflow_path: String,
250    /// The git ref.
251    pub git_ref: String,
252    /// The input mappings.
253    pub input_mappings: HashMap<String, String>,
254}
255
256#[derive(Debug, Deserialize, ToSchema)]
257/// Createcronworkflowrequest.
258pub struct CreateCronWorkflowRequest {
259    /// The name.
260    pub name: String,
261    /// The description.
262    pub description: Option<String>,
263    /// The cronspec.
264    pub cronspec: String,
265    /// The workflow name.
266    pub workflow_name: String,
267    /// The repo url.
268    pub repo_url: String,
269    /// The workflow path.
270    pub workflow_path: String,
271    /// The git ref.
272    pub git_ref: String,
273    /// The inputs.
274    #[schema(value_type = Object)]
275    pub inputs: Value,
276}
277
278#[derive(Debug, Serialize, ToSchema)]
279/// Cronworkflowresponse.
280pub struct CronWorkflowResponse {
281    /// The id.
282    pub id: stormchaser_model::CronWorkflowId,
283    /// The secret token.
284    pub secret_token: String,
285    /// The external job id.
286    pub external_job_id: Option<String>,
287}
288
289#[derive(Debug, Deserialize, ToSchema)]
290/// Createstoragebackendrequest.
291pub struct CreateStorageBackendRequest {
292    /// The name.
293    pub name: String,
294    /// The description.
295    pub description: Option<String>,
296    /// The backend type.
297    pub backend_type: BackendType,
298    /// The config.
299    #[schema(value_type = Object)]
300    pub config: Value,
301    /// Optional AWS role ARN.
302    pub aws_assume_role_arn: Option<String>,
303    /// The is default sfs.
304    pub is_default_sfs: bool,
305}
306
307#[derive(Debug, Deserialize, ToSchema)]
308/// Updatestoragebackendrequest.
309pub struct UpdateStorageBackendRequest {
310    /// The name.
311    pub name: Option<String>,
312    /// The description.
313    pub description: Option<String>,
314    /// The backend type.
315    pub backend_type: Option<BackendType>,
316    /// The config.
317    #[schema(value_type = Object)]
318    pub config: Option<Value>,
319    /// Optional AWS role ARN. Set to an empty string to clear an existing ARN.
320    pub aws_assume_role_arn: Option<String>,
321    /// The is default sfs.
322    pub is_default_sfs: Option<bool>,
323}
324
325#[derive(Debug, Serialize, Deserialize, sqlx::FromRow, ToSchema)]
326/// Testreportsummary.
327pub struct TestReportSummary {
328    /// The id.
329    pub id: stormchaser_model::TestReportId,
330    /// The report name.
331    pub report_name: String,
332    /// The file name.
333    pub file_name: String,
334    /// The format.
335    pub format: String,
336    /// The checksum.
337    pub checksum: String,
338    /// The backend id.
339    pub backend_id: Option<stormchaser_model::BackendId>,
340    /// The remote path.
341    pub remote_path: Option<String>,
342    /// The created at.
343    pub created_at: DateTime<Utc>,
344}
345
346#[derive(Debug, Serialize, Deserialize, sqlx::FromRow, ToSchema)]
347/// Testsummaryresponse.
348pub struct TestSummaryResponse {
349    /// The id.
350    pub id: stormchaser_model::TestReportId,
351    /// The run id.
352    pub run_id: stormchaser_model::RunId,
353    /// The step instance id.
354    pub step_instance_id: stormchaser_model::StepInstanceId,
355    /// The report name.
356    pub report_name: String,
357    /// The total tests.
358    pub total_tests: i32,
359    /// The passed.
360    pub passed: i32,
361    /// The failed.
362    pub failed: i32,
363    /// The skipped.
364    pub skipped: i32,
365    /// The errors.
366    pub errors: i32,
367    /// The duration ms.
368    pub duration_ms: i64,
369    /// The created at.
370    pub created_at: DateTime<Utc>,
371}