Skip to content
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 52 additions & 6 deletions server/src/storage/s3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,28 @@ pub struct S3Config {
long,
env = "P_S3_ACCESS_KEY",
value_name = "access-key",
required = true
required_unless_present = "profile_name"
)]
pub access_key_id: String,
pub access_key_id: Option<String>,

/// The secret key for AWS S3 or compatible object storage platform
#[arg(
long,
env = "P_S3_SECRET_KEY",
value_name = "secret-key",
required = true
required_unless_present = "profile_name"
)]
pub secret_key: String,
pub secret_key: Option<String>,

// Use aws profile name to fetch credentials
#[arg(
long,
env = "P_AWS_PROFILE_NAME",
value_name = "profile",
conflicts_with_all = ["access_key_id", "secret_key"],
required = false
)]
pub profile_name: Option<String>,

/// The region for AWS S3 or compatible object storage platform
#[arg(long, env = "P_S3_REGION", value_name = "region", required = true)]
Expand Down Expand Up @@ -119,6 +129,24 @@ pub struct S3Config {
default_value = "false"
)]
pub skip_tls: bool,

/// Set client to fallback to imdsv1
#[arg(
long,
env = "P_AWS_IMDSV1_FALLBACK",
value_name = "bool",
default_value = "false"
)]
pub imdsv1_fallback: bool,

/// Set instance metadata endpoint to use.
#[arg(
long,
env = "P_AWS_METADATA_ENDPOINT",
value_name = "url",
required = false
)]
pub metadata_endpoint: Option<String>,
}

impl S3Config {
Expand All @@ -135,15 +163,33 @@ impl S3Config {
.with_region(&self.region)
.with_endpoint(&self.endpoint_url)
.with_bucket_name(&self.bucket_name)
.with_access_key_id(&self.access_key_id)
.with_secret_access_key(&self.secret_key)
.with_virtual_hosted_style_request(!self.use_path_style)
.with_allow_http(true);

if self.set_checksum {
builder = builder.with_checksum_algorithm(Checksum::SHA256)
}

if let Some((access_key, secret_key)) =
self.access_key_id.as_ref().zip(self.secret_key.as_ref())
{
builder = builder
.with_access_key_id(access_key)
.with_secret_access_key(secret_key);
}

if let Some(profile) = &self.profile_name {
builder = builder.with_profile(profile);
}

if self.imdsv1_fallback {
builder = builder.with_imdsv1_fallback()
}

if let Some(metadata_endpoint) = &self.metadata_endpoint {
builder = builder.with_metadata_endpoint(metadata_endpoint)
}

builder.with_client_options(client_options)
}
}
Expand Down