fundaia 0.52.2

Command line for the Fundaia deployment platform: projects, services, variables, deployments, logs and metrics
use super::*;

impl ApiClient {
    pub async fn shared_variables(&self, project_id: &str) -> Result<Answer<SharedVariablesPage>> {
        self.get_answer(&format!(
            "/api/infra/projects/{project_id}/variables{}",
            self.environment_query('?')
        ))
        .await
    }

    pub async fn set_shared_variable(
        &self,
        project_id: &str,
        key: &str,
        value: &str,
        secret: bool,
        environment_only: bool,
    ) -> Result<Answer<serde_json::Value>> {
        self.answer(
            Method::PUT,
            &format!(
                "/api/infra/projects/{project_id}/variables{}",
                self.environment_query('?')
            ),
            Some(&serde_json::json!({
                "key": key,
                "value": value,
                "secret": secret,
                "scope": if environment_only { "environment" } else { "project" },
            })),
        )
        .await
    }

    pub async fn unset_shared_variable(
        &self,
        project_id: &str,
        key: &str,
        environment_only: bool,
    ) -> Result<Answer<serde_json::Value>> {
        let scope = if environment_only {
            "environment"
        } else {
            "project"
        };
        let environment = self.environment_query('&');
        self.answer(
            Method::DELETE,
            &format!(
                "/api/infra/projects/{project_id}/variables/{}?scope={scope}{environment}",
                utf8_percent_encode(key, NON_ALPHANUMERIC)
            ),
            None::<&()>,
        )
        .await
    }
}