tapis-pods 0.3.1

The Pods Service is a web service and distributed computing platform providing pods-as-a-service (PaaS). The service implements a message broker and processor model that requests pods, alongside a health module to poll for pod data, including logs, status, and health. The primary use of this service is to have quick to deploy long-lived services based on Docker images that are exposed via HTTP or TCP endpoints listed by the API. **The Pods service provides functionality for two types of pod solutions:** * **Templated Pods** for run-as-is popular images. Neo4J is one example, the template manages TCP ports, user creation, and permissions. * **Custom Pods** for arbitrary docker images with less functionality. In this case we will expose port 5000 and do nothing else. The live-docs act as the most up-to-date API reference. Visit the [documentation for more information](https://tapis.readthedocs.io/en/latest/technical/pods.html).
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
use crate::apis::{
    configuration, images_api, jupyter_api, misc_api, permissions_api, pods_api, secrets_api,
    snapshots_api, templates_api, volumes_api, Error,
};
use crate::models;
use http::header::{HeaderMap, HeaderValue};
use reqwest::{Client, Request, Response};
use reqwest_middleware::{ClientBuilder, Middleware, Next, Result as MiddlewareResult};
use std::sync::Arc;
use tapis_core::TokenProvider;

tokio::task_local! {
    /// Extra headers to inject into every request within a [`with_headers`] scope.
    static EXTRA_HEADERS: HeaderMap;
}

/// Run an async call with additional HTTP headers injected into every request
/// made within the future `f`. Headers are scoped to this task only, so
/// concurrent calls with different headers are safe.
pub async fn with_headers<F, T>(headers: HeaderMap, f: F) -> T
where
    F: std::future::Future<Output = T>,
{
    EXTRA_HEADERS.scope(headers, f).await
}

#[derive(Debug)]
struct LoggingMiddleware;

#[derive(Debug)]
struct HeaderInjectionMiddleware;

#[async_trait::async_trait]
impl Middleware for LoggingMiddleware {
    async fn handle(
        &self,
        req: Request,
        extensions: &mut http::Extensions,
        next: Next<'_>,
    ) -> MiddlewareResult<Response> {
        let method = req.method().clone();
        let url = req.url().clone();
        println!("Tapis SDK request: {} {}", method, url);
        next.run(req, extensions).await
    }
}

#[async_trait::async_trait]
impl Middleware for HeaderInjectionMiddleware {
    async fn handle(
        &self,
        mut req: Request,
        extensions: &mut http::Extensions,
        next: Next<'_>,
    ) -> MiddlewareResult<Response> {
        let _ = EXTRA_HEADERS.try_with(|headers| {
            for (k, v) in headers {
                req.headers_mut().insert(k, v.clone());
            }
        });
        next.run(req, extensions).await
    }
}

fn validate_tracking_id(tracking_id: &str) -> Result<(), String> {
    if !tracking_id.is_ascii() {
        return Err("X-Tapis-Tracking-ID must be an entirely ASCII string.".to_string());
    }
    if tracking_id.len() > 126 {
        return Err("X-Tapis-Tracking-ID must be less than 126 characters.".to_string());
    }
    if tracking_id.matches('.').count() != 1 {
        return Err("X-Tapis-Tracking-ID must contain exactly one '.' (format: <namespace>.<unique_identifier>).".to_string());
    }
    if tracking_id.starts_with('.') || tracking_id.ends_with('.') {
        return Err("X-Tapis-Tracking-ID cannot start or end with '.'.".to_string());
    }
    let (namespace, unique_id) = tracking_id.split_once('.').unwrap();
    if !namespace.chars().all(|c| c.is_alphanumeric() || c == '_') {
        return Err("X-Tapis-Tracking-ID namespace must contain only alphanumeric characters and underscores.".to_string());
    }
    if !unique_id.chars().all(|c| c.is_alphanumeric() || c == '-') {
        return Err("X-Tapis-Tracking-ID unique identifier must contain only alphanumeric characters and hyphens.".to_string());
    }
    Ok(())
}

#[derive(Debug)]
struct TrackingIdMiddleware;

#[async_trait::async_trait]
impl Middleware for TrackingIdMiddleware {
    async fn handle(
        &self,
        mut req: Request,
        extensions: &mut http::Extensions,
        next: Next<'_>,
    ) -> MiddlewareResult<Response> {
        let tracking_key = req
            .headers()
            .keys()
            .find(|k| {
                let s = k.as_str();
                s.eq_ignore_ascii_case("x-tapis-tracking-id")
                    || s.eq_ignore_ascii_case("x_tapis_tracking_id")
            })
            .cloned();
        if let Some(key) = tracking_key {
            let tracking_id = req
                .headers()
                .get(&key)
                .and_then(|v| v.to_str().ok())
                .map(|s| s.to_owned());
            if let Some(id) = tracking_id {
                req.headers_mut().remove(&key);
                validate_tracking_id(&id)
                    .map_err(|e| reqwest_middleware::Error::Middleware(anyhow::anyhow!(e)))?;
                let name = reqwest::header::HeaderName::from_static("x-tapis-tracking-id");
                let value = reqwest::header::HeaderValue::from_str(&id)
                    .map_err(|e| reqwest_middleware::Error::Middleware(anyhow::anyhow!(e)))?;
                req.headers_mut().insert(name, value);
            }
        }
        next.run(req, extensions).await
    }
}

/// Decode a base64url-encoded segment (no padding required) into raw bytes.
fn decode_base64url(s: &str) -> Option<Vec<u8>> {
    fn val(c: u8) -> Option<u8> {
        match c {
            b'A'..=b'Z' => Some(c - b'A'),
            b'a'..=b'z' => Some(c - b'a' + 26),
            b'0'..=b'9' => Some(c - b'0' + 52),
            b'-' | b'+' => Some(62),
            b'_' | b'/' => Some(63),
            _ => None,
        }
    }
    let chars: Vec<u8> = s.bytes().filter(|&b| b != b'=').collect();
    let mut out = Vec::with_capacity(chars.len() * 3 / 4 + 1);
    let mut i = 0;
    while i < chars.len() {
        let a = val(chars[i])?;
        let b = val(*chars.get(i + 1)?)?;
        out.push((a << 2) | (b >> 4));
        if let Some(&c3) = chars.get(i + 2) {
            let c = val(c3)?;
            out.push(((b & 0x0f) << 4) | (c >> 2));
            if let Some(&c4) = chars.get(i + 3) {
                let d = val(c4)?;
                out.push(((c & 0x03) << 6) | d);
            }
        }
        i += 4;
    }
    Some(out)
}

/// Extract the `exp` (expiration) claim from a JWT without verifying the signature.
fn extract_jwt_exp(token: &str) -> Option<i64> {
    let payload_b64 = token.split('.').nth(1)?;
    let bytes = decode_base64url(payload_b64)?;
    let claims: serde_json::Value = serde_json::from_slice(&bytes).ok()?;
    claims.get("exp")?.as_i64()
}

struct RefreshMiddleware {
    token_provider: Arc<dyn TokenProvider>,
}

#[async_trait::async_trait]
impl Middleware for RefreshMiddleware {
    async fn handle(
        &self,
        mut req: Request,
        extensions: &mut http::Extensions,
        next: Next<'_>,
    ) -> MiddlewareResult<Response> {
        let is_token_endpoint = {
            let url = req.url().as_str();
            url.contains("/oauth2/tokens") || url.contains("/v3/tokens")
        };
        if !is_token_endpoint {
            let needs_refresh = req
                .headers()
                .get("x-tapis-token")
                .and_then(|v| v.to_str().ok())
                .and_then(extract_jwt_exp)
                .map(|exp| {
                    let now = std::time::SystemTime::now()
                        .duration_since(std::time::UNIX_EPOCH)
                        .map(|d| d.as_secs() as i64)
                        .unwrap_or(0);
                    exp - now < 5
                })
                .unwrap_or(false);
            if needs_refresh {
                if let Some(new_token) = self.token_provider.get_token().await {
                    let value = HeaderValue::from_str(&new_token)
                        .map_err(|e| reqwest_middleware::Error::Middleware(anyhow::anyhow!(e)))?;
                    req.headers_mut().insert("x-tapis-token", value);
                }
            }
        }
        next.run(req, extensions).await
    }
}

#[derive(Clone)]
pub struct TapisPods {
    config: Arc<configuration::Configuration>,
    pub images: ImagesClient,
    pub jupyter: JupyterClient,
    pub misc: MiscClient,
    pub permissions: PermissionsClient,
    pub pods: PodsClient,
    pub secrets: SecretsClient,
    pub snapshots: SnapshotsClient,
    pub templates: TemplatesClient,
    pub volumes: VolumesClient,
}

impl TapisPods {
    pub fn new(
        base_url: &str,
        jwt_token: Option<&str>,
    ) -> Result<Self, Box<dyn std::error::Error>> {
        Self::build(base_url, jwt_token, None)
    }

    /// Create a client with a [`TokenProvider`] for automatic token refresh.
    /// `RefreshMiddleware` is added to the middleware chain and will call
    /// `provider.get_token()` transparently whenever the JWT is about to expire.
    pub fn with_token_provider(
        base_url: &str,
        jwt_token: Option<&str>,
        provider: Arc<dyn TokenProvider>,
    ) -> Result<Self, Box<dyn std::error::Error>> {
        Self::build(base_url, jwt_token, Some(provider))
    }

    fn build(
        base_url: &str,
        jwt_token: Option<&str>,
        token_provider: Option<Arc<dyn TokenProvider>>,
    ) -> Result<Self, Box<dyn std::error::Error>> {
        let mut headers = HeaderMap::new();
        if let Some(token) = jwt_token {
            headers.insert("X-Tapis-Token", HeaderValue::from_str(token)?);
        }

        let reqwest_client = Client::builder().default_headers(headers).build()?;

        let mut builder = ClientBuilder::new(reqwest_client)
            .with(LoggingMiddleware)
            .with(HeaderInjectionMiddleware)
            .with(TrackingIdMiddleware);

        if let Some(provider) = token_provider {
            builder = builder.with(RefreshMiddleware {
                token_provider: provider,
            });
        }

        let client = builder.build();

        let config = Arc::new(configuration::Configuration {
            base_path: base_url.to_string(),
            client,
            ..Default::default()
        });

        Ok(Self {
            config: config.clone(),
            images: ImagesClient {
                config: config.clone(),
            },
            jupyter: JupyterClient {
                config: config.clone(),
            },
            misc: MiscClient {
                config: config.clone(),
            },
            permissions: PermissionsClient {
                config: config.clone(),
            },
            pods: PodsClient {
                config: config.clone(),
            },
            secrets: SecretsClient {
                config: config.clone(),
            },
            snapshots: SnapshotsClient {
                config: config.clone(),
            },
            templates: TemplatesClient {
                config: config.clone(),
            },
            volumes: VolumesClient {
                config: config.clone(),
            },
        })
    }

    pub fn config(&self) -> &configuration::Configuration {
        &self.config
    }
}

#[derive(Clone)]
pub struct ImagesClient {
    config: Arc<configuration::Configuration>,
}

impl ImagesClient {
    pub async fn add_image(
        &self,
        new_image: models::NewImage,
    ) -> Result<models::ImageResponse, Error<images_api::AddImageError>> {
        images_api::add_image(&self.config, new_image).await
    }

    pub async fn add_images(
        &self,
        new_image: Vec<models::NewImage>,
        skip_duplicates: Option<bool>,
    ) -> Result<models::ImagesResponse, Error<images_api::AddImagesError>> {
        images_api::add_images(&self.config, new_image, skip_duplicates).await
    }

    pub async fn delete_image(
        &self,
        image_id: &str,
    ) -> Result<models::ImageDeleteResponse, Error<images_api::DeleteImageError>> {
        images_api::delete_image(&self.config, image_id).await
    }

    pub async fn get_image(
        &self,
        image_id: &str,
    ) -> Result<models::ResponseGetImage, Error<images_api::GetImageError>> {
        images_api::get_image(&self.config, image_id).await
    }

    pub async fn get_images(
        &self,
    ) -> Result<models::ImagesResponse, Error<images_api::GetImagesError>> {
        images_api::get_images(&self.config).await
    }

    pub async fn update_image(
        &self,
        image_id: &str,
        update_image: models::UpdateImage,
    ) -> Result<models::ImageResponse, Error<images_api::UpdateImageError>> {
        images_api::update_image(&self.config, image_id, update_image).await
    }
}

#[derive(Clone)]
pub struct JupyterClient {
    config: Arc<configuration::Configuration>,
}

impl JupyterClient {
    pub async fn ensure_jupyter_pod(
        &self,
    ) -> Result<serde_json::Value, Error<jupyter_api::EnsureJupyterPodError>> {
        jupyter_api::ensure_jupyter_pod(&self.config).await
    }

    pub async fn upload_to_jupyter(
        &self,
        pod_id: &str,
        file: std::path::PathBuf,
        path: &str,
    ) -> Result<serde_json::Value, Error<jupyter_api::UploadToJupyterError>> {
        jupyter_api::upload_to_jupyter(&self.config, pod_id, file, path).await
    }
}

#[derive(Clone)]
pub struct MiscClient {
    config: Arc<configuration::Configuration>,
}

impl MiscClient {
    pub async fn error_handler(
        &self,
        status: &str,
    ) -> Result<serde_json::Value, Error<misc_api::ErrorHandlerError>> {
        misc_api::error_handler(&self.config, status).await
    }

    pub async fn healthcheck(
        &self,
    ) -> Result<serde_json::Value, Error<misc_api::HealthcheckError>> {
        misc_api::healthcheck(&self.config).await
    }

    pub async fn traefik_config(
        &self,
    ) -> Result<serde_json::Value, Error<misc_api::TraefikConfigError>> {
        misc_api::traefik_config(&self.config).await
    }
}

#[derive(Clone)]
pub struct PermissionsClient {
    config: Arc<configuration::Configuration>,
}

impl PermissionsClient {
    pub async fn delete_pod_permission(
        &self,
        pod_id: &str,
        user: &str,
    ) -> Result<models::PodPermissionsResponse, Error<permissions_api::DeletePodPermissionError>>
    {
        permissions_api::delete_pod_permission(&self.config, pod_id, user).await
    }

    pub async fn delete_snapshot_permission(
        &self,
        snapshot_id: &str,
        user: &str,
    ) -> Result<
        models::SnapshotPermissionsResponse,
        Error<permissions_api::DeleteSnapshotPermissionError>,
    > {
        permissions_api::delete_snapshot_permission(&self.config, snapshot_id, user).await
    }

    pub async fn delete_template_permission(
        &self,
        template_id: &str,
        user: &str,
    ) -> Result<
        models::TemplatePermissionsResponse,
        Error<permissions_api::DeleteTemplatePermissionError>,
    > {
        permissions_api::delete_template_permission(&self.config, template_id, user).await
    }

    pub async fn delete_volume_permission(
        &self,
        volume_id: &str,
        user: &str,
    ) -> Result<
        models::VolumePermissionsResponse,
        Error<permissions_api::DeleteVolumePermissionError>,
    > {
        permissions_api::delete_volume_permission(&self.config, volume_id, user).await
    }

    pub async fn get_pod_permissions(
        &self,
        pod_id: &str,
    ) -> Result<models::PodPermissionsResponse, Error<permissions_api::GetPodPermissionsError>>
    {
        permissions_api::get_pod_permissions(&self.config, pod_id).await
    }

    pub async fn get_snapshot_permissions(
        &self,
        snapshot_id: &str,
    ) -> Result<
        models::SnapshotPermissionsResponse,
        Error<permissions_api::GetSnapshotPermissionsError>,
    > {
        permissions_api::get_snapshot_permissions(&self.config, snapshot_id).await
    }

    pub async fn get_template_permissions(
        &self,
        template_id: &str,
    ) -> Result<
        models::TemplatePermissionsResponse,
        Error<permissions_api::GetTemplatePermissionsError>,
    > {
        permissions_api::get_template_permissions(&self.config, template_id).await
    }

    pub async fn get_volume_permissions(
        &self,
        volume_id: &str,
    ) -> Result<models::VolumePermissionsResponse, Error<permissions_api::GetVolumePermissionsError>>
    {
        permissions_api::get_volume_permissions(&self.config, volume_id).await
    }

    pub async fn set_pod_permission(
        &self,
        pod_id: &str,
        set_permission: models::SetPermission,
    ) -> Result<models::PodPermissionsResponse, Error<permissions_api::SetPodPermissionError>> {
        permissions_api::set_pod_permission(&self.config, pod_id, set_permission).await
    }

    pub async fn set_snapshot_permission(
        &self,
        snapshot_id: &str,
        set_permission: models::SetPermission,
    ) -> Result<
        models::SnapshotPermissionsResponse,
        Error<permissions_api::SetSnapshotPermissionError>,
    > {
        permissions_api::set_snapshot_permission(&self.config, snapshot_id, set_permission).await
    }

    pub async fn set_template_permission(
        &self,
        template_id: &str,
        set_permission: models::SetPermission,
    ) -> Result<
        models::TemplatePermissionsResponse,
        Error<permissions_api::SetTemplatePermissionError>,
    > {
        permissions_api::set_template_permission(&self.config, template_id, set_permission).await
    }

    pub async fn set_volume_permission(
        &self,
        volume_id: &str,
        set_permission: models::SetPermission,
    ) -> Result<models::VolumePermissionsResponse, Error<permissions_api::SetVolumePermissionError>>
    {
        permissions_api::set_volume_permission(&self.config, volume_id, set_permission).await
    }
}

#[derive(Clone)]
pub struct PodsClient {
    config: Arc<configuration::Configuration>,
}

impl PodsClient {
    pub async fn create_pod(
        &self,
        new_pod: models::NewPod,
    ) -> Result<models::PodResponse, Error<pods_api::CreatePodError>> {
        pods_api::create_pod(&self.config, new_pod).await
    }

    pub async fn delete_pod(
        &self,
        pod_id: &str,
    ) -> Result<models::PodDeleteResponse, Error<pods_api::DeletePodError>> {
        pods_api::delete_pod(&self.config, pod_id).await
    }

    pub async fn download_from_pod(
        &self,
        pod_id: &str,
        url_path: &str,
        path: Option<&str>,
    ) -> Result<serde_json::Value, Error<pods_api::DownloadFromPodError>> {
        pods_api::download_from_pod(&self.config, pod_id, url_path, path).await
    }

    pub async fn exec_pod_commands(
        &self,
        pod_id: &str,
        execute_pod_commands: models::ExecutePodCommands,
    ) -> Result<serde_json::Value, Error<pods_api::ExecPodCommandsError>> {
        pods_api::exec_pod_commands(&self.config, pod_id, execute_pod_commands).await
    }

    pub async fn get_derived_pod(
        &self,
        pod_id: &str,
        include_configs: Option<bool>,
        resolve_secrets: Option<bool>,
    ) -> Result<models::PodResponse, Error<pods_api::GetDerivedPodError>> {
        pods_api::get_derived_pod(&self.config, pod_id, include_configs, resolve_secrets).await
    }

    pub async fn get_pod(
        &self,
        pod_id: &str,
        include_configs: Option<bool>,
        check_unresolved: Option<bool>,
    ) -> Result<models::PodResponse, Error<pods_api::GetPodError>> {
        pods_api::get_pod(&self.config, pod_id, include_configs, check_unresolved).await
    }

    pub async fn get_pod_credentials(
        &self,
        pod_id: &str,
    ) -> Result<models::PodCredentialsResponse, Error<pods_api::GetPodCredentialsError>> {
        pods_api::get_pod_credentials(&self.config, pod_id).await
    }

    pub async fn get_pod_logs(
        &self,
        pod_id: &str,
    ) -> Result<models::PodLogsResponse, Error<pods_api::GetPodLogsError>> {
        pods_api::get_pod_logs(&self.config, pod_id).await
    }

    pub async fn list_files_in_pod(
        &self,
        pod_id: &str,
        url_path: &str,
        path: Option<&str>,
    ) -> Result<serde_json::Value, Error<pods_api::ListFilesInPodError>> {
        pods_api::list_files_in_pod(&self.config, pod_id, url_path, path).await
    }

    pub async fn list_pods(&self) -> Result<models::PodsResponse, Error<pods_api::ListPodsError>> {
        pods_api::list_pods(&self.config).await
    }

    pub async fn pod_auth(
        &self,
        pod_id_net: &str,
    ) -> Result<models::PodResponse, Error<pods_api::PodAuthError>> {
        pods_api::pod_auth(&self.config, pod_id_net).await
    }

    pub async fn pod_auth_callback(
        &self,
        pod_id_net: &str,
    ) -> Result<models::PodResponse, Error<pods_api::PodAuthCallbackError>> {
        pods_api::pod_auth_callback(&self.config, pod_id_net).await
    }

    pub async fn restart_pod(
        &self,
        pod_id: &str,
        grab_latest_template_tag: Option<bool>,
    ) -> Result<models::PodResponse, Error<pods_api::RestartPodError>> {
        pods_api::restart_pod(&self.config, pod_id, grab_latest_template_tag).await
    }

    pub async fn save_pod_as_template_tag(
        &self,
        pod_id_net: &str,
        new_template_tag_from_pod: models::NewTemplateTagFromPod,
    ) -> Result<models::TemplateTagResponse, Error<pods_api::SavePodAsTemplateTagError>> {
        pods_api::save_pod_as_template_tag(&self.config, pod_id_net, new_template_tag_from_pod)
            .await
    }

    pub async fn start_pod(
        &self,
        pod_id: &str,
    ) -> Result<models::PodResponse, Error<pods_api::StartPodError>> {
        pods_api::start_pod(&self.config, pod_id).await
    }

    pub async fn stop_pod(
        &self,
        pod_id: &str,
    ) -> Result<models::PodResponse, Error<pods_api::StopPodError>> {
        pods_api::stop_pod(&self.config, pod_id).await
    }

    pub async fn update_pod(
        &self,
        pod_id: &str,
        update_pod: models::UpdatePod,
    ) -> Result<models::PodResponse, Error<pods_api::UpdatePodError>> {
        pods_api::update_pod(&self.config, pod_id, update_pod).await
    }

    pub async fn upload_to_pod(
        &self,
        pod_id: &str,
        file: std::path::PathBuf,
        dest_path: &str,
    ) -> Result<serde_json::Value, Error<pods_api::UploadToPodError>> {
        pods_api::upload_to_pod(&self.config, pod_id, file, dest_path).await
    }
}

#[derive(Clone)]
pub struct SecretsClient {
    config: Arc<configuration::Configuration>,
}

impl SecretsClient {
    pub async fn create_secret(
        &self,
        new_secret: models::NewSecret,
    ) -> Result<models::SecretResponse, Error<secrets_api::CreateSecretError>> {
        secrets_api::create_secret(&self.config, new_secret).await
    }

    pub async fn delete_secret(
        &self,
        secret_id: &str,
    ) -> Result<models::SecretDeleteResponse, Error<secrets_api::DeleteSecretError>> {
        secrets_api::delete_secret(&self.config, secret_id).await
    }

    pub async fn get_secret(
        &self,
        secret_id: &str,
    ) -> Result<models::SecretResponse, Error<secrets_api::GetSecretError>> {
        secrets_api::get_secret(&self.config, secret_id).await
    }

    pub async fn get_secret_value(
        &self,
        secret_id: &str,
    ) -> Result<models::SecretValueResponse, Error<secrets_api::GetSecretValueError>> {
        secrets_api::get_secret_value(&self.config, secret_id).await
    }

    pub async fn list_secrets(
        &self,
    ) -> Result<models::SecretsResponse, Error<secrets_api::ListSecretsError>> {
        secrets_api::list_secrets(&self.config).await
    }

    pub async fn update_secret(
        &self,
        secret_id: &str,
        update_secret: models::UpdateSecret,
    ) -> Result<models::SecretResponse, Error<secrets_api::UpdateSecretError>> {
        secrets_api::update_secret(&self.config, secret_id, update_secret).await
    }
}

#[derive(Clone)]
pub struct SnapshotsClient {
    config: Arc<configuration::Configuration>,
}

impl SnapshotsClient {
    pub async fn create_snapshot(
        &self,
        new_snapshot: models::NewSnapshot,
    ) -> Result<models::SnapshotResponse, Error<snapshots_api::CreateSnapshotError>> {
        snapshots_api::create_snapshot(&self.config, new_snapshot).await
    }

    pub async fn delete_snapshot(
        &self,
        snapshot_id: &str,
    ) -> Result<models::DeleteSnapshotResponse, Error<snapshots_api::DeleteSnapshotError>> {
        snapshots_api::delete_snapshot(&self.config, snapshot_id).await
    }

    pub async fn download_snapshot_file(
        &self,
        snapshot_id: &str,
        path: &str,
    ) -> Result<serde_json::Value, Error<snapshots_api::DownloadSnapshotFileError>> {
        snapshots_api::download_snapshot_file(&self.config, snapshot_id, path).await
    }

    pub async fn get_snapshot(
        &self,
        snapshot_id: &str,
    ) -> Result<models::SnapshotResponse, Error<snapshots_api::GetSnapshotError>> {
        snapshots_api::get_snapshot(&self.config, snapshot_id).await
    }

    pub async fn get_snapshot_contents(
        &self,
        snapshot_id: &str,
        path: &str,
        zip: Option<bool>,
    ) -> Result<serde_json::Value, Error<snapshots_api::GetSnapshotContentsError>> {
        snapshots_api::get_snapshot_contents(&self.config, snapshot_id, path, zip).await
    }

    pub async fn list_snapshot_files(
        &self,
        snapshot_id: &str,
    ) -> Result<models::FilesListResponse, Error<snapshots_api::ListSnapshotFilesError>> {
        snapshots_api::list_snapshot_files(&self.config, snapshot_id).await
    }

    pub async fn list_snapshots(
        &self,
    ) -> Result<models::SnapshotsResponse, Error<snapshots_api::ListSnapshotsError>> {
        snapshots_api::list_snapshots(&self.config).await
    }

    pub async fn update_snapshot(
        &self,
        snapshot_id: &str,
        update_snapshot: models::UpdateSnapshot,
    ) -> Result<models::SnapshotResponse, Error<snapshots_api::UpdateSnapshotError>> {
        snapshots_api::update_snapshot(&self.config, snapshot_id, update_snapshot).await
    }
}

#[derive(Clone)]
pub struct TemplatesClient {
    config: Arc<configuration::Configuration>,
}

impl TemplatesClient {
    pub async fn add_template(
        &self,
        new_template: models::NewTemplate,
    ) -> Result<models::TemplateResponse, Error<templates_api::AddTemplateError>> {
        templates_api::add_template(&self.config, new_template).await
    }

    pub async fn add_template_tag(
        &self,
        template_id: &str,
        new_template_tag: models::NewTemplateTag,
    ) -> Result<models::TemplateTagResponse, Error<templates_api::AddTemplateTagError>> {
        templates_api::add_template_tag(&self.config, template_id, new_template_tag).await
    }

    pub async fn delete_template(
        &self,
        template_id: &str,
    ) -> Result<models::TemplateDeleteResponse, Error<templates_api::DeleteTemplateError>> {
        templates_api::delete_template(&self.config, template_id).await
    }

    pub async fn delete_template_tag(
        &self,
        template_id: &str,
        tag_id: &str,
        force: Option<bool>,
    ) -> Result<models::TemplateTagDeleteResponse, Error<templates_api::DeleteTemplateTagError>>
    {
        templates_api::delete_template_tag(&self.config, template_id, tag_id, force).await
    }

    pub async fn get_template(
        &self,
        template_id: &str,
        include_dependencies: Option<bool>,
    ) -> Result<models::ResponseGetTemplate, Error<templates_api::GetTemplateError>> {
        templates_api::get_template(&self.config, template_id, include_dependencies).await
    }

    pub async fn get_template_tag(
        &self,
        template_id: &str,
        tag_id: &str,
        include_configs: Option<bool>,
        include_dependencies: Option<bool>,
    ) -> Result<models::ResponseGetTemplateTag, Error<templates_api::GetTemplateTagError>> {
        templates_api::get_template_tag(
            &self.config,
            template_id,
            tag_id,
            include_configs,
            include_dependencies,
        )
        .await
    }

    pub async fn list_template_tags(
        &self,
        template_id: &str,
        full: Option<bool>,
        include_configs: Option<bool>,
        include_dependencies: Option<bool>,
    ) -> Result<models::ResponseListTemplateTags, Error<templates_api::ListTemplateTagsError>> {
        templates_api::list_template_tags(
            &self.config,
            template_id,
            full,
            include_configs,
            include_dependencies,
        )
        .await
    }

    pub async fn list_templates(
        &self,
        include_dependencies: Option<bool>,
    ) -> Result<models::ResponseListTemplates, Error<templates_api::ListTemplatesError>> {
        templates_api::list_templates(&self.config, include_dependencies).await
    }

    pub async fn list_templates_and_tags(
        &self,
        full: Option<bool>,
        include_dependencies: Option<bool>,
    ) -> Result<
        std::collections::HashMap<String, serde_json::Value>,
        Error<templates_api::ListTemplatesAndTagsError>,
    > {
        templates_api::list_templates_and_tags(&self.config, full, include_dependencies).await
    }

    pub async fn update_template(
        &self,
        template_id: &str,
        update_template: models::UpdateTemplate,
    ) -> Result<models::TemplateResponse, Error<templates_api::UpdateTemplateError>> {
        templates_api::update_template(&self.config, template_id, update_template).await
    }
}

#[derive(Clone)]
pub struct VolumesClient {
    config: Arc<configuration::Configuration>,
}

impl VolumesClient {
    pub async fn create_volume(
        &self,
        new_volume: models::NewVolume,
    ) -> Result<models::VolumeResponse, Error<volumes_api::CreateVolumeError>> {
        volumes_api::create_volume(&self.config, new_volume).await
    }

    pub async fn delete_volume(
        &self,
        volume_id: &str,
    ) -> Result<models::DeleteVolumeResponse, Error<volumes_api::DeleteVolumeError>> {
        volumes_api::delete_volume(&self.config, volume_id).await
    }

    pub async fn download_volume_file(
        &self,
        volume_id: &str,
        path: &str,
    ) -> Result<serde_json::Value, Error<volumes_api::DownloadVolumeFileError>> {
        volumes_api::download_volume_file(&self.config, volume_id, path).await
    }

    pub async fn get_volume(
        &self,
        volume_id: &str,
    ) -> Result<models::VolumeResponse, Error<volumes_api::GetVolumeError>> {
        volumes_api::get_volume(&self.config, volume_id).await
    }

    pub async fn get_volume_contents(
        &self,
        volume_id: &str,
        path: &str,
        zip: Option<bool>,
    ) -> Result<serde_json::Value, Error<volumes_api::GetVolumeContentsError>> {
        volumes_api::get_volume_contents(&self.config, volume_id, path, zip).await
    }

    pub async fn list_volume_files(
        &self,
        volume_id: &str,
    ) -> Result<models::FilesListResponse, Error<volumes_api::ListVolumeFilesError>> {
        volumes_api::list_volume_files(&self.config, volume_id).await
    }

    pub async fn list_volumes(
        &self,
    ) -> Result<models::VolumesResponse, Error<volumes_api::ListVolumesError>> {
        volumes_api::list_volumes(&self.config).await
    }

    pub async fn update_volume(
        &self,
        volume_id: &str,
        update_volume: models::UpdateVolume,
    ) -> Result<models::VolumeResponse, Error<volumes_api::UpdateVolumeError>> {
        volumes_api::update_volume(&self.config, volume_id, update_volume).await
    }

    pub async fn upload_to_volume(
        &self,
        volume_id: &str,
        path: &str,
        file: std::path::PathBuf,
    ) -> Result<models::FilesUploadResponse, Error<volumes_api::UploadToVolumeError>> {
        volumes_api::upload_to_volume(&self.config, volume_id, path, file).await
    }
}