wasmer_cli/commands/app/cdn/
mod.rs

1//! Manage app CDN cache.
2
3use super::util::AppIdentOpts;
4use crate::{commands::AsyncCliCommand, config::WasmerEnv};
5
6pub mod disable;
7pub mod enable;
8pub mod purge;
9pub mod status;
10
11/// Manage CDN cache for an app.
12#[derive(clap::Subcommand, Debug)]
13pub enum CmdAppCdn {
14    Enable(enable::CmdAppCdnEnable),
15    Disable(disable::CmdAppCdnDisable),
16    Status(status::CmdAppCdnStatus),
17    Purge(purge::CmdAppCdnPurge),
18}
19
20#[async_trait::async_trait]
21impl AsyncCliCommand for CmdAppCdn {
22    type Output = ();
23
24    async fn run_async(self) -> Result<Self::Output, anyhow::Error> {
25        match self {
26            Self::Enable(cmd) => cmd.run_async().await,
27            Self::Disable(cmd) => cmd.run_async().await,
28            Self::Status(cmd) => cmd.run_async().await,
29            Self::Purge(cmd) => cmd.run_async().await,
30        }
31    }
32}
33
34async fn configure_cdn_cache(
35    env: WasmerEnv,
36    ident: AppIdentOpts,
37    enabled: bool,
38) -> Result<(), anyhow::Error> {
39    let client = env.client()?;
40    let (_ident, app) = ident.load_app(&client).await?;
41
42    let payload = wasmer_backend_api::query::configure_app_cdn_cache(
43        &client,
44        wasmer_backend_api::types::ConfigureAppCdnCacheVars {
45            app: app.id,
46            enabled: Some(enabled),
47        },
48    )
49    .await?;
50
51    anyhow::ensure!(
52        payload.success,
53        "CDN cache configuration update was not successful"
54    );
55
56    println!(
57        "CDN cache {}.",
58        if enabled { "enabled" } else { "disabled" }
59    );
60
61    Ok(())
62}