platz_sdk/resources/
helm_chart.rs

1use crate::client::PlatzClient;
2use anyhow::{bail, Result};
3use chrono::prelude::*;
4use kv_derive::{prelude::*, IntoVec};
5use serde::Deserialize;
6use uuid::Uuid;
7
8#[derive(Debug, Deserialize, Clone)]
9pub struct HelmChart {
10    pub id: Uuid,
11    pub created_at: DateTime<Utc>,
12    pub helm_registry_id: Uuid,
13    pub image_digest: String,
14    pub image_tag: String,
15    pub available: bool,
16    pub values_ui: Option<platz_chart_ext::UiSchema>,
17    pub actions_schema: Option<platz_chart_ext::ChartExtActions>,
18    pub features: Option<platz_chart_ext::ChartExtFeatures>,
19    pub resource_types: Option<serde_json::Value>,
20    pub error: Option<String>,
21    pub tag_format_id: Option<Uuid>,
22    pub parsed_version: Option<String>,
23    pub parsed_revision: Option<String>,
24    pub parsed_branch: Option<String>,
25    pub parsed_commit: Option<String>,
26}
27
28impl HelmChart {
29    pub fn get_actions_schema(&self) -> Result<platz_chart_ext::ChartExtActions> {
30        match self.actions_schema.as_ref() {
31            Some(schema) => Ok(schema.clone()),
32            None => bail!("No actions schema for helm chart"),
33        }
34    }
35
36    pub fn get_actions(&self) -> Result<Vec<platz_chart_ext::ChartExtActionV0>> {
37        Ok(if let Some(actions_schema) = self.actions_schema.as_ref() {
38            actions_schema.get_actions()
39        } else {
40            Vec::new()
41        })
42    }
43}
44
45#[derive(Default, IntoVec)]
46pub struct HelmChartFilters {
47    #[kv(optional)]
48    pub helm_registry_id: Option<Uuid>,
49    #[kv(optional)]
50    pub parsed_branch: Option<String>,
51    #[kv(optional)]
52    pub in_use: Option<bool>,
53    #[kv(optional)]
54    pub kind_id: Option<Uuid>,
55}
56
57impl PlatzClient {
58    pub async fn helm_charts(&self, filters: HelmChartFilters) -> Result<Vec<HelmChart>> {
59        Ok(self
60            .request(reqwest::Method::GET, "/api/v2/helm-charts")
61            .add_to_query(filters.into_vec())
62            .paginated()
63            .await?)
64    }
65    pub async fn helm_chart(&self, helm_chart_id: Uuid) -> Result<HelmChart> {
66        Ok(self
67            .request(
68                reqwest::Method::GET,
69                format!("/api/v2/helm-charts/{helm_chart_id}"),
70            )
71            .send()
72            .await?)
73    }
74}