1use crate::apis::{
2 archives_api, cicd_api, configuration, etl_api, general_api, group_secrets_api, groups_api,
3 identities_api, pipeline_archives_api, pipeline_locks_api, pipeline_runs_api, pipelines_api,
4 secrets_api, task_executions_api, tasks_api, users_api, Error,
5};
6use crate::models;
7use http::header::{HeaderMap, HeaderValue};
8use reqwest::{Client, Request, Response};
9use reqwest_middleware::{ClientBuilder, Middleware, Next, Result as MiddlewareResult};
10use std::sync::Arc;
11
12#[derive(Debug)]
13struct LoggingMiddleware;
14
15#[async_trait::async_trait]
16impl Middleware for LoggingMiddleware {
17 async fn handle(
18 &self,
19 req: Request,
20 extensions: &mut http::Extensions,
21 next: Next<'_>,
22 ) -> MiddlewareResult<Response> {
23 let method = req.method().clone();
24 let url = req.url().clone();
25 println!("Tapis SDK request: {} {}", method, url);
26 next.run(req, extensions).await
27 }
28}
29
30#[derive(Clone)]
31pub struct TapisWorkflows {
32 config: Arc<configuration::Configuration>,
33 pub archives: ArchivesClient,
34 pub cicd: CicdClient,
35 pub etl: EtlClient,
36 pub general: GeneralClient,
37 pub group_secrets: GroupSecretsClient,
38 pub groups: GroupsClient,
39 pub identities: IdentitiesClient,
40 pub pipeline_archives: PipelineArchivesClient,
41 pub pipeline_locks: PipelineLocksClient,
42 pub pipeline_runs: PipelineRunsClient,
43 pub pipelines: PipelinesClient,
44 pub secrets: SecretsClient,
45 pub task_executions: TaskExecutionsClient,
46 pub tasks: TasksClient,
47 pub users: UsersClient,
48}
49
50impl TapisWorkflows {
51 pub fn new(
52 base_url: &str,
53 jwt_token: Option<&str>,
54 ) -> Result<Self, Box<dyn std::error::Error>> {
55 let mut headers = HeaderMap::new();
56 if let Some(token) = jwt_token {
57 headers.insert("X-Tapis-Token", HeaderValue::from_str(token)?);
58 }
59
60 let reqwest_client = Client::builder().default_headers(headers).build()?;
61
62 let client = ClientBuilder::new(reqwest_client)
63 .with(LoggingMiddleware)
64 .build();
65
66 let mut config = configuration::Configuration::default();
67 config.base_path = base_url.to_string();
68 config.client = client;
69
70 let config = Arc::new(config);
71
72 Ok(Self {
73 config: config.clone(),
74 archives: ArchivesClient {
75 config: config.clone(),
76 },
77 cicd: CicdClient {
78 config: config.clone(),
79 },
80 etl: EtlClient {
81 config: config.clone(),
82 },
83 general: GeneralClient {
84 config: config.clone(),
85 },
86 group_secrets: GroupSecretsClient {
87 config: config.clone(),
88 },
89 groups: GroupsClient {
90 config: config.clone(),
91 },
92 identities: IdentitiesClient {
93 config: config.clone(),
94 },
95 pipeline_archives: PipelineArchivesClient {
96 config: config.clone(),
97 },
98 pipeline_locks: PipelineLocksClient {
99 config: config.clone(),
100 },
101 pipeline_runs: PipelineRunsClient {
102 config: config.clone(),
103 },
104 pipelines: PipelinesClient {
105 config: config.clone(),
106 },
107 secrets: SecretsClient {
108 config: config.clone(),
109 },
110 task_executions: TaskExecutionsClient {
111 config: config.clone(),
112 },
113 tasks: TasksClient {
114 config: config.clone(),
115 },
116 users: UsersClient {
117 config: config.clone(),
118 },
119 })
120 }
121
122 pub fn config(&self) -> &configuration::Configuration {
123 &self.config
124 }
125}
126
127#[derive(Clone)]
128pub struct ArchivesClient {
129 config: Arc<configuration::Configuration>,
130}
131
132impl ArchivesClient {
133 pub async fn create_archive(
134 &self,
135 group_id: &str,
136 req_archive: models::ReqArchive,
137 ) -> Result<models::RespResourceUrl, Error<archives_api::CreateArchiveError>> {
138 archives_api::create_archive(&self.config, group_id, req_archive).await
139 }
140
141 pub async fn get_archive(
142 &self,
143 group_id: &str,
144 archive_id: &str,
145 ) -> Result<models::RespArchive, Error<archives_api::GetArchiveError>> {
146 archives_api::get_archive(&self.config, group_id, archive_id).await
147 }
148
149 pub async fn list_archives(
150 &self,
151 group_id: &str,
152 ) -> Result<models::RespArchiveList, Error<archives_api::ListArchivesError>> {
153 archives_api::list_archives(&self.config, group_id).await
154 }
155}
156
157#[derive(Clone)]
158pub struct CicdClient {
159 config: Arc<configuration::Configuration>,
160}
161
162impl CicdClient {
163 pub async fn create_ci_pipeline(
164 &self,
165 group_id: &str,
166 req_ci_pipeline: models::ReqCiPipeline,
167 ) -> Result<models::RespResourceUrl, Error<cicd_api::CreateCiPipelineError>> {
168 cicd_api::create_ci_pipeline(&self.config, group_id, req_ci_pipeline).await
169 }
170}
171
172#[derive(Clone)]
173pub struct EtlClient {
174 config: Arc<configuration::Configuration>,
175}
176
177impl EtlClient {
178 pub async fn create_etl_pipeline(
179 &self,
180 group_id: &str,
181 req_create_etl_pipeline: models::ReqCreateEtlPipeline,
182 ) -> Result<models::RespResourceUrl, Error<etl_api::CreateEtlPipelineError>> {
183 etl_api::create_etl_pipeline(&self.config, group_id, req_create_etl_pipeline).await
184 }
185}
186
187#[derive(Clone)]
188pub struct GeneralClient {
189 config: Arc<configuration::Configuration>,
190}
191
192impl GeneralClient {
193 pub async fn health_check(
194 &self,
195 ) -> Result<models::RespBase, Error<general_api::HealthCheckError>> {
196 general_api::health_check(&self.config).await
197 }
198}
199
200#[derive(Clone)]
201pub struct GroupSecretsClient {
202 config: Arc<configuration::Configuration>,
203}
204
205impl GroupSecretsClient {
206 pub async fn add_group_secret(
207 &self,
208 group_id: &str,
209 req_group_secret: models::ReqGroupSecret,
210 ) -> Result<models::RespGroupSecret, Error<group_secrets_api::AddGroupSecretError>> {
211 group_secrets_api::add_group_secret(&self.config, group_id, req_group_secret).await
212 }
213
214 pub async fn get_group_secret(
215 &self,
216 group_id: &str,
217 group_secret_id: &str,
218 ) -> Result<models::RespGroupSecret, Error<group_secrets_api::GetGroupSecretError>> {
219 group_secrets_api::get_group_secret(&self.config, group_id, group_secret_id).await
220 }
221
222 pub async fn list_group_secrets(
223 &self,
224 group_id: &str,
225 ) -> Result<models::RespGroupSecretList, Error<group_secrets_api::ListGroupSecretsError>> {
226 group_secrets_api::list_group_secrets(&self.config, group_id).await
227 }
228
229 pub async fn remove_group_secret(
230 &self,
231 group_id: &str,
232 group_secret_id: &str,
233 ) -> Result<models::RespBase, Error<group_secrets_api::RemoveGroupSecretError>> {
234 group_secrets_api::remove_group_secret(&self.config, group_id, group_secret_id).await
235 }
236}
237
238#[derive(Clone)]
239pub struct GroupsClient {
240 config: Arc<configuration::Configuration>,
241}
242
243impl GroupsClient {
244 pub async fn create_group(
245 &self,
246 req_group: models::ReqGroup,
247 ) -> Result<models::RespResourceUrl, Error<groups_api::CreateGroupError>> {
248 groups_api::create_group(&self.config, req_group).await
249 }
250
251 pub async fn delete_group(
252 &self,
253 group_id: &str,
254 ) -> Result<models::RespString, Error<groups_api::DeleteGroupError>> {
255 groups_api::delete_group(&self.config, group_id).await
256 }
257
258 pub async fn get_group(
259 &self,
260 group_id: &str,
261 ) -> Result<models::RespGroupDetail, Error<groups_api::GetGroupError>> {
262 groups_api::get_group(&self.config, group_id).await
263 }
264
265 pub async fn list_groups(
266 &self,
267 ) -> Result<models::RespGroupList, Error<groups_api::ListGroupsError>> {
268 groups_api::list_groups(&self.config).await
269 }
270}
271
272#[derive(Clone)]
273pub struct IdentitiesClient {
274 config: Arc<configuration::Configuration>,
275}
276
277impl IdentitiesClient {
278 pub async fn create_identity(
279 &self,
280 req_identity: models::ReqIdentity,
281 ) -> Result<models::RespResourceUrl, Error<identities_api::CreateIdentityError>> {
282 identities_api::create_identity(&self.config, req_identity).await
283 }
284
285 pub async fn delete_identity(
286 &self,
287 identity_uuid: &str,
288 ) -> Result<models::RespString, Error<identities_api::DeleteIdentityError>> {
289 identities_api::delete_identity(&self.config, identity_uuid).await
290 }
291
292 pub async fn get_identity(
293 &self,
294 identity_uuid: &str,
295 ) -> Result<models::RespIdentity, Error<identities_api::GetIdentityError>> {
296 identities_api::get_identity(&self.config, identity_uuid).await
297 }
298
299 pub async fn list_identities(
300 &self,
301 ) -> Result<models::RespIdentityList, Error<identities_api::ListIdentitiesError>> {
302 identities_api::list_identities(&self.config).await
303 }
304}
305
306#[derive(Clone)]
307pub struct PipelineArchivesClient {
308 config: Arc<configuration::Configuration>,
309}
310
311impl PipelineArchivesClient {
312 pub async fn list_pipeline_archives(
313 &self,
314 group_id: &str,
315 pipeline_id: &str,
316 ) -> Result<models::RespArchiveList, Error<pipeline_archives_api::ListPipelineArchivesError>>
317 {
318 pipeline_archives_api::list_pipeline_archives(&self.config, group_id, pipeline_id).await
319 }
320}
321
322#[derive(Clone)]
323pub struct PipelineLocksClient {
324 config: Arc<configuration::Configuration>,
325}
326
327impl PipelineLocksClient {
328 pub async fn get_pipeline_lock(
329 &self,
330 group_id: &str,
331 pipeline_id: &str,
332 pipeline_lock_uuid: &str,
333 ) -> Result<models::RespPipelineLock, Error<pipeline_locks_api::GetPipelineLockError>> {
334 pipeline_locks_api::get_pipeline_lock(
335 &self.config,
336 group_id,
337 pipeline_id,
338 pipeline_lock_uuid,
339 )
340 .await
341 }
342
343 pub async fn list_pipeline_locks(
344 &self,
345 group_id: &str,
346 pipeline_id: &str,
347 ) -> Result<models::RespPipelineLockList, Error<pipeline_locks_api::ListPipelineLocksError>>
348 {
349 pipeline_locks_api::list_pipeline_locks(&self.config, group_id, pipeline_id).await
350 }
351
352 pub async fn release_pipeline_lock(
353 &self,
354 group_id: &str,
355 pipeline_id: &str,
356 pipeline_run_uuid: &str,
357 ) -> Result<(), Error<pipeline_locks_api::ReleasePipelineLockError>> {
358 pipeline_locks_api::release_pipeline_lock(
359 &self.config,
360 group_id,
361 pipeline_id,
362 pipeline_run_uuid,
363 )
364 .await
365 }
366}
367
368#[derive(Clone)]
369pub struct PipelineRunsClient {
370 config: Arc<configuration::Configuration>,
371}
372
373impl PipelineRunsClient {
374 pub async fn acquire_pipeline_lock(
375 &self,
376 group_id: &str,
377 pipeline_id: &str,
378 pipeline_run_uuid: &str,
379 req_pipeline_lock: models::ReqPipelineLock,
380 ) -> Result<
381 models::RespPipelineLockAcquisition,
382 Error<pipeline_runs_api::AcquirePipelineLockError>,
383 > {
384 pipeline_runs_api::acquire_pipeline_lock(
385 &self.config,
386 group_id,
387 pipeline_id,
388 pipeline_run_uuid,
389 req_pipeline_lock,
390 )
391 .await
392 }
393
394 pub async fn get_pipeline_run(
395 &self,
396 group_id: &str,
397 pipeline_id: &str,
398 pipeline_run_uuid: &str,
399 ) -> Result<models::RespPipelineRun, Error<pipeline_runs_api::GetPipelineRunError>> {
400 pipeline_runs_api::get_pipeline_run(&self.config, group_id, pipeline_id, pipeline_run_uuid)
401 .await
402 }
403
404 pub async fn list_pipeline_runs(
405 &self,
406 group_id: &str,
407 pipeline_id: &str,
408 ) -> Result<models::RespPipelineRunList, Error<pipeline_runs_api::ListPipelineRunsError>> {
409 pipeline_runs_api::list_pipeline_runs(&self.config, group_id, pipeline_id).await
410 }
411
412 pub async fn terminate_pipeline(
413 &self,
414 group_id: &str,
415 pipeline_id: &str,
416 pipeline_run_uuid: &str,
417 ) -> Result<models::RespPipelineRun, Error<pipeline_runs_api::TerminatePipelineError>> {
418 pipeline_runs_api::terminate_pipeline(
419 &self.config,
420 group_id,
421 pipeline_id,
422 pipeline_run_uuid,
423 )
424 .await
425 }
426
427 pub async fn update_pipeline_run_status(
428 &self,
429 x_workflow_executor_token: &str,
430 pipeline_run_uuid: &str,
431 status: models::EnumRunStatus,
432 req_patch_pipeline_run: Option<models::ReqPatchPipelineRun>,
433 ) -> Result<models::RespString, Error<pipeline_runs_api::UpdatePipelineRunStatusError>> {
434 pipeline_runs_api::update_pipeline_run_status(
435 &self.config,
436 x_workflow_executor_token,
437 pipeline_run_uuid,
438 status,
439 req_patch_pipeline_run,
440 )
441 .await
442 }
443}
444
445#[derive(Clone)]
446pub struct PipelinesClient {
447 config: Arc<configuration::Configuration>,
448}
449
450impl PipelinesClient {
451 pub async fn add_pipeline_archive(
452 &self,
453 group_id: &str,
454 pipeline_id: &str,
455 ) -> Result<models::RespBase, Error<pipelines_api::AddPipelineArchiveError>> {
456 pipelines_api::add_pipeline_archive(&self.config, group_id, pipeline_id).await
457 }
458
459 pub async fn change_pipeline_owner(
460 &self,
461 group_id: &str,
462 pipeline_id: &str,
463 username: &str,
464 ) -> Result<models::RespBase, Error<pipelines_api::ChangePipelineOwnerError>> {
465 pipelines_api::change_pipeline_owner(&self.config, group_id, pipeline_id, username).await
466 }
467
468 pub async fn create_pipeline(
469 &self,
470 group_id: &str,
471 req_pipeline: models::ReqPipeline,
472 ) -> Result<models::RespResourceUrl, Error<pipelines_api::CreatePipelineError>> {
473 pipelines_api::create_pipeline(&self.config, group_id, req_pipeline).await
474 }
475
476 pub async fn delete_pipeline(
477 &self,
478 group_id: &str,
479 pipeline_id: &str,
480 ) -> Result<models::RespString, Error<pipelines_api::DeletePipelineError>> {
481 pipelines_api::delete_pipeline(&self.config, group_id, pipeline_id).await
482 }
483
484 pub async fn get_pipeline(
485 &self,
486 group_id: &str,
487 pipeline_id: &str,
488 ) -> Result<models::RespPipeline, Error<pipelines_api::GetPipelineError>> {
489 pipelines_api::get_pipeline(&self.config, group_id, pipeline_id).await
490 }
491
492 pub async fn list_pipelines(
493 &self,
494 group_id: &str,
495 ) -> Result<models::RespPipelineList, Error<pipelines_api::ListPipelinesError>> {
496 pipelines_api::list_pipelines(&self.config, group_id).await
497 }
498
499 pub async fn remove_pipeline_archive(
500 &self,
501 group_id: &str,
502 pipeline_id: &str,
503 ) -> Result<models::RespBase, Error<pipelines_api::RemovePipelineArchiveError>> {
504 pipelines_api::remove_pipeline_archive(&self.config, group_id, pipeline_id).await
505 }
506
507 pub async fn run_pipeline(
508 &self,
509 group_id: &str,
510 pipeline_id: &str,
511 req_run_pipeline: models::ReqRunPipeline,
512 ) -> Result<models::RespPipelineRun, Error<pipelines_api::RunPipelineError>> {
513 pipelines_api::run_pipeline(&self.config, group_id, pipeline_id, req_run_pipeline).await
514 }
515}
516
517#[derive(Clone)]
518pub struct SecretsClient {
519 config: Arc<configuration::Configuration>,
520}
521
522impl SecretsClient {
523 pub async fn create_secret(
524 &self,
525 req_create_secret: models::ReqCreateSecret,
526 ) -> Result<models::RespSecret, Error<secrets_api::CreateSecretError>> {
527 secrets_api::create_secret(&self.config, req_create_secret).await
528 }
529
530 pub async fn delete_secret(
531 &self,
532 secret_id: &str,
533 ) -> Result<models::RespString, Error<secrets_api::DeleteSecretError>> {
534 secrets_api::delete_secret(&self.config, secret_id).await
535 }
536
537 pub async fn get_secret(
538 &self,
539 secret_id: &str,
540 ) -> Result<models::RespSecret, Error<secrets_api::GetSecretError>> {
541 secrets_api::get_secret(&self.config, secret_id).await
542 }
543
544 pub async fn list_secrets(
545 &self,
546 ) -> Result<models::RespSecretList, Error<secrets_api::ListSecretsError>> {
547 secrets_api::list_secrets(&self.config).await
548 }
549}
550
551#[derive(Clone)]
552pub struct TaskExecutionsClient {
553 config: Arc<configuration::Configuration>,
554}
555
556impl TaskExecutionsClient {
557 pub async fn create_task_execution(
558 &self,
559 x_workflow_executor_token: &str,
560 pipeline_run_uuid: &str,
561 req_create_task_execution: models::ReqCreateTaskExecution,
562 ) -> Result<models::RespResourceUrl, Error<task_executions_api::CreateTaskExecutionError>> {
563 task_executions_api::create_task_execution(
564 &self.config,
565 x_workflow_executor_token,
566 pipeline_run_uuid,
567 req_create_task_execution,
568 )
569 .await
570 }
571
572 pub async fn get_task_execution(
573 &self,
574 group_id: &str,
575 pipeline_id: &str,
576 pipeline_run_uuid: &str,
577 task_execution_uuid: &str,
578 ) -> Result<models::RespTaskExecution, Error<task_executions_api::GetTaskExecutionError>> {
579 task_executions_api::get_task_execution(
580 &self.config,
581 group_id,
582 pipeline_id,
583 pipeline_run_uuid,
584 task_execution_uuid,
585 )
586 .await
587 }
588
589 pub async fn list_task_executions(
590 &self,
591 group_id: &str,
592 pipeline_id: &str,
593 pipeline_run_uuid: &str,
594 ) -> Result<models::RespTaskExecutionList, Error<task_executions_api::ListTaskExecutionsError>>
595 {
596 task_executions_api::list_task_executions(
597 &self.config,
598 group_id,
599 pipeline_id,
600 pipeline_run_uuid,
601 )
602 .await
603 }
604
605 pub async fn update_task_execution_status(
606 &self,
607 x_workflow_executor_token: &str,
608 task_execution_uuid: &str,
609 status: models::EnumRunStatus,
610 req_patch_task_execution: Option<models::ReqPatchTaskExecution>,
611 ) -> Result<models::RespString, Error<task_executions_api::UpdateTaskExecutionStatusError>>
612 {
613 task_executions_api::update_task_execution_status(
614 &self.config,
615 x_workflow_executor_token,
616 task_execution_uuid,
617 status,
618 req_patch_task_execution,
619 )
620 .await
621 }
622}
623
624#[derive(Clone)]
625pub struct TasksClient {
626 config: Arc<configuration::Configuration>,
627}
628
629impl TasksClient {
630 pub async fn create_task(
631 &self,
632 group_id: &str,
633 pipeline_id: &str,
634 req_task: models::ReqTask,
635 ) -> Result<models::RespResourceUrl, Error<tasks_api::CreateTaskError>> {
636 tasks_api::create_task(&self.config, group_id, pipeline_id, req_task).await
637 }
638
639 pub async fn delete_task(
640 &self,
641 group_id: &str,
642 pipeline_id: &str,
643 task_id: &str,
644 ) -> Result<models::RespString, Error<tasks_api::DeleteTaskError>> {
645 tasks_api::delete_task(&self.config, group_id, pipeline_id, task_id).await
646 }
647
648 pub async fn get_task(
649 &self,
650 group_id: &str,
651 pipeline_id: &str,
652 task_id: &str,
653 ) -> Result<models::RespTask, Error<tasks_api::GetTaskError>> {
654 tasks_api::get_task(&self.config, group_id, pipeline_id, task_id).await
655 }
656
657 pub async fn list_tasks(
658 &self,
659 group_id: &str,
660 pipeline_id: &str,
661 ) -> Result<models::RespTaskList, Error<tasks_api::ListTasksError>> {
662 tasks_api::list_tasks(&self.config, group_id, pipeline_id).await
663 }
664
665 pub async fn patch_task(
666 &self,
667 group_id: &str,
668 pipeline_id: &str,
669 task_id: &str,
670 task: models::Task,
671 ) -> Result<models::RespTask, Error<tasks_api::PatchTaskError>> {
672 tasks_api::patch_task(&self.config, group_id, pipeline_id, task_id, task).await
673 }
674}
675
676#[derive(Clone)]
677pub struct UsersClient {
678 config: Arc<configuration::Configuration>,
679}
680
681impl UsersClient {
682 pub async fn add_group_user(
683 &self,
684 group_id: &str,
685 req_group_user: models::ReqGroupUser,
686 ) -> Result<models::RespResourceUrl, Error<users_api::AddGroupUserError>> {
687 users_api::add_group_user(&self.config, group_id, req_group_user).await
688 }
689
690 pub async fn get_group_user(
691 &self,
692 group_id: &str,
693 username: &str,
694 ) -> Result<models::RespGroupUser, Error<users_api::GetGroupUserError>> {
695 users_api::get_group_user(&self.config, group_id, username).await
696 }
697
698 pub async fn list_group_users(
699 &self,
700 group_id: &str,
701 ) -> Result<models::RespGroupUserList, Error<users_api::ListGroupUsersError>> {
702 users_api::list_group_users(&self.config, group_id).await
703 }
704
705 pub async fn remove_group_user(
706 &self,
707 group_id: &str,
708 username: &str,
709 ) -> Result<models::RespGroupUser, Error<users_api::RemoveGroupUserError>> {
710 users_api::remove_group_user(&self.config, group_id, username).await
711 }
712
713 pub async fn update_group_user(
714 &self,
715 group_id: &str,
716 username: &str,
717 req_update_group_user: models::ReqUpdateGroupUser,
718 ) -> Result<models::RespGroupUser, Error<users_api::UpdateGroupUserError>> {
719 users_api::update_group_user(&self.config, group_id, username, req_update_group_user).await
720 }
721}