diff --git a/lib/backend-api/src/query.rs b/lib/backend-api/src/query.rs index 4f784394ecb..de0d32877cb 100644 --- a/lib/backend-api/src/query.rs +++ b/lib/backend-api/src/query.rs @@ -214,7 +214,7 @@ pub async fn get_app_volumes( /// Retrieved with [`get_app_s3_credentials`]. #[derive(Clone)] pub struct AppS3Credentials { - pub domain: String, + pub url: String, pub access_key: String, pub secret_key: String, } @@ -262,7 +262,7 @@ pub async fn get_app_s3_credentials( .with_context(|| format!("No value found for secret with name '{}'", SECRET_KEY_NAME))?; Ok(AppS3Credentials { - domain: url.0, + url: url.0, access_key, secret_key, }) diff --git a/lib/cli/src/commands/app/volumes/s3_credentials.rs b/lib/cli/src/commands/app/volumes/s3_credentials.rs index 0949902ddd9..abfd378924d 100644 --- a/lib/cli/src/commands/app/volumes/s3_credentials.rs +++ b/lib/cli/src/commands/app/volumes/s3_credentials.rs @@ -7,6 +7,11 @@ use super::super::util::AppIdentOpts; use crate::{commands::AsyncCliCommand, config::WasmerEnv, opts::ItemFormatOpts}; /// Retrieve S3 access credentials for the volumes of an app. +/// +/// The S3 credentials can be used to access volumes with any S3 client, +/// for example rclone. +/// +/// Note that --rclone-print will output an rclone configuration snippet. #[derive(clap::Parser, Debug)] pub struct CmdAppS3Credentials { #[clap(flatten)] @@ -17,6 +22,13 @@ pub struct CmdAppS3Credentials { #[clap(flatten)] pub ident: AppIdentOpts, + + /// Print rclone configuration. + /// + /// The output can be added the rclone configuration file, which is + /// usually located at `~/.config/rclone/rclone.conf`. + #[clap(long)] + pub rclone_print: bool, } #[async_trait::async_trait] @@ -30,12 +42,35 @@ impl AsyncCliCommand for CmdAppS3Credentials { 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."); + if self.rclone_print { + let rclone_config = format!( + r#" +[edge-{app_name}] +type = s3 +provider = Other +acl = private +access_key_id = {access_key} +secret_access_key = {secret_key} +endpoint = {endpoint} + + "#, + app_name = app.name, + access_key = creds.access_key, + secret_key = creds.secret_key, + endpoint = creds.url, + ); + + println!("{}", rclone_config); + } else { + println!("S3 credentials for app {}:\n", app.name); + println!(" S3 URL: {}", creds.url); + println!(" Access key: {}", creds.access_key); + println!(" Secret key: {}", creds.secret_key); + println!(); + println!("Hint: use --rclone-print to generate configuration for the rclone S3 client"); + println!("Consult the app volumes documentation for more information."); + println!(); + } Ok(app) }