fundaia 0.52.1

Command line for the Fundaia deployment platform: projects, services, variables, deployments, logs and metrics
//! Maintenance mode and the password in front of a service: what the gateway answers first.

use super::*;

impl ApiClient {
    pub async fn set_maintenance(
        &self,
        service_environment_id: &str,
        enabled: bool,
        message: Option<&str>,
    ) -> Result<Answer<EdgeAccessPage>> {
        let mut body = serde_json::Map::new();
        body.insert("enabled".into(), enabled.into());
        if let Some(message) = message {
            body.insert("message".into(), message.into());
        }
        self.answer(
            Method::PUT,
            &format!("/api/infra/services/{service_environment_id}/maintenance"),
            Some(&serde_json::Value::Object(body)),
        )
        .await
    }

    pub async fn protect_service(
        &self,
        service_environment_id: &str,
        username: &str,
        password: &str,
    ) -> Result<Answer<EdgeAccessPage>> {
        self.answer(
            Method::PUT,
            &format!("/api/infra/services/{service_environment_id}/protection"),
            Some(&serde_json::json!({ "username": username, "password": password })),
        )
        .await
    }

    pub async fn unprotect_service(
        &self,
        service_environment_id: &str,
    ) -> Result<Answer<EdgeAccessPage>> {
        self.answer(
            Method::DELETE,
            &format!("/api/infra/services/{service_environment_id}/protection"),
            None::<&()>,
        )
        .await
    }
}