Skip to content

Commit 1b052c2

Browse files
authored
Use aws_profile to fetch credentials (#380)
1 parent 065eec6 commit 1b052c2

File tree

2 files changed

+53
-7
lines changed

2 files changed

+53
-7
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/src/storage/s3.rs

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,28 @@ pub struct S3Config {
7272
long,
7373
env = "P_S3_ACCESS_KEY",
7474
value_name = "access-key",
75-
required = true
75+
required_unless_present = "profile_name"
7676
)]
77-
pub access_key_id: String,
77+
pub access_key_id: Option<String>,
7878

7979
/// The secret key for AWS S3 or compatible object storage platform
8080
#[arg(
8181
long,
8282
env = "P_S3_SECRET_KEY",
8383
value_name = "secret-key",
84-
required = true
84+
required_unless_present = "profile_name"
8585
)]
86-
pub secret_key: String,
86+
pub secret_key: Option<String>,
87+
88+
// Use aws profile name to fetch credentials
89+
#[arg(
90+
long,
91+
env = "P_AWS_PROFILE_NAME",
92+
value_name = "profile",
93+
conflicts_with_all = ["access_key_id", "secret_key"],
94+
required = false
95+
)]
96+
pub profile_name: Option<String>,
8797

8898
/// The region for AWS S3 or compatible object storage platform
8999
#[arg(long, env = "P_S3_REGION", value_name = "region", required = true)]
@@ -119,6 +129,24 @@ pub struct S3Config {
119129
default_value = "false"
120130
)]
121131
pub skip_tls: bool,
132+
133+
/// Set client to fallback to imdsv1
134+
#[arg(
135+
long,
136+
env = "P_AWS_IMDSV1_FALLBACK",
137+
value_name = "bool",
138+
default_value = "false"
139+
)]
140+
pub imdsv1_fallback: bool,
141+
142+
/// Set instance metadata endpoint to use.
143+
#[arg(
144+
long,
145+
env = "P_AWS_METADATA_ENDPOINT",
146+
value_name = "url",
147+
required = false
148+
)]
149+
pub metadata_endpoint: Option<String>,
122150
}
123151

124152
impl S3Config {
@@ -135,15 +163,33 @@ impl S3Config {
135163
.with_region(&self.region)
136164
.with_endpoint(&self.endpoint_url)
137165
.with_bucket_name(&self.bucket_name)
138-
.with_access_key_id(&self.access_key_id)
139-
.with_secret_access_key(&self.secret_key)
140166
.with_virtual_hosted_style_request(!self.use_path_style)
141167
.with_allow_http(true);
142168

143169
if self.set_checksum {
144170
builder = builder.with_checksum_algorithm(Checksum::SHA256)
145171
}
146172

173+
if let Some((access_key, secret_key)) =
174+
self.access_key_id.as_ref().zip(self.secret_key.as_ref())
175+
{
176+
builder = builder
177+
.with_access_key_id(access_key)
178+
.with_secret_access_key(secret_key);
179+
}
180+
181+
if let Some(profile) = &self.profile_name {
182+
builder = builder.with_profile(profile);
183+
}
184+
185+
if self.imdsv1_fallback {
186+
builder = builder.with_imdsv1_fallback()
187+
}
188+
189+
if let Some(metadata_endpoint) = &self.metadata_endpoint {
190+
builder = builder.with_metadata_endpoint(metadata_endpoint)
191+
}
192+
147193
builder.with_client_options(client_options)
148194
}
149195
}

0 commit comments

Comments
 (0)