-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): Add "app volumes" commands
- Loading branch information
Showing
5 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//! List Edge apps. | ||
use super::super::util::AppIdentOpts; | ||
use crate::{commands::AsyncCliCommand, config::WasmerEnv, opts::ListFormatOpts}; | ||
|
||
/// List the volumes of an app. | ||
#[derive(clap::Parser, Debug)] | ||
pub struct CmdAppVolumesList { | ||
#[clap(flatten)] | ||
fmt: ListFormatOpts, | ||
|
||
#[clap(flatten)] | ||
env: WasmerEnv, | ||
|
||
#[clap(flatten)] | ||
ident: AppIdentOpts, | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl AsyncCliCommand for CmdAppVolumesList { | ||
type Output = (); | ||
|
||
async fn run_async(self) -> Result<(), anyhow::Error> { | ||
let client = self.env.client()?; | ||
|
||
let (_ident, app) = self.ident.load_app(&client).await?; | ||
let volumes = | ||
wasmer_api::query::get_app_volumes(&client, &app.owner.global_name, &app.name).await?; | ||
|
||
if volumes.is_empty() { | ||
eprintln!("App {} has no volumes!", app.name); | ||
} else { | ||
println!("{}", self.fmt.format.render(volumes.as_slice())); | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use crate::commands::AsyncCliCommand; | ||
|
||
pub mod list; | ||
pub mod s3_credentials; | ||
|
||
/// App volume management. | ||
#[derive(Debug, clap::Parser)] | ||
pub enum CmdAppVolumes { | ||
S3Credentials(s3_credentials::CmdAppS3Credentials), | ||
List(list::CmdAppVolumesList), | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl AsyncCliCommand for CmdAppVolumes { | ||
type Output = (); | ||
|
||
async fn run_async(self) -> Result<Self::Output, anyhow::Error> { | ||
match self { | ||
Self::S3Credentials(c) => { | ||
c.run_async().await?; | ||
Ok(()) | ||
} | ||
Self::List(c) => { | ||
c.run_async().await?; | ||
Ok(()) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
//! Get information about an edge app. | ||
use wasmer_api::types::DeployApp; | ||
|
||
use super::super::util::AppIdentOpts; | ||
|
||
use crate::{commands::AsyncCliCommand, config::WasmerEnv, opts::ItemFormatOpts}; | ||
|
||
/// Retrieve S3 access credentials for the volumes of an app. | ||
#[derive(clap::Parser, Debug)] | ||
pub struct CmdAppS3Credentials { | ||
#[clap(flatten)] | ||
pub env: WasmerEnv, | ||
|
||
#[clap(flatten)] | ||
pub fmt: ItemFormatOpts, | ||
|
||
#[clap(flatten)] | ||
pub ident: AppIdentOpts, | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl AsyncCliCommand for CmdAppS3Credentials { | ||
type Output = DeployApp; | ||
|
||
async fn run_async(self) -> Result<DeployApp, anyhow::Error> { | ||
let client = self.env.client()?; | ||
let (_ident, app) = self.ident.load_app(&client).await?; | ||
|
||
let creds = | ||
wasmer_api::query::get_app_s3_credentials(&client, app.id.clone().into_inner()).await?; | ||
|
||
println!("S3 credentials for app {}:\n", app.name); | ||
println!(" S3 URL: https://{}", creds.domain); | ||
println!(" Access key: {}", creds.access_key); | ||
println!(" Secret key: {}", creds.secret_key); | ||
println!(); | ||
println!("Consult the app volumes documentation for more information."); | ||
|
||
Ok(app) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters