Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): Add --print-rclone-config to "app volumes s3-credentials" #5022

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/backend-api/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
})
Expand Down
47 changes: 41 additions & 6 deletions lib/cli/src/commands/app/volumes/s3_credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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]
Expand All @@ -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)
}
Expand Down
Loading