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