Skip to content

Commit

Permalink
feat: parse endpoint_url from profile and env (#497)
Browse files Browse the repository at this point in the history
  • Loading branch information
TennyZhuang authored Nov 4, 2024
1 parent 0da8d62 commit a69c2b6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions services/aws-v4/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ pub struct Config {
/// - this field
/// - env value: [`AWS_EC2_METADATA_DISABLED`]
pub ec2_metadata_disabled: bool,
/// `endpoint_url` value will be loaded from:
///
/// - this field
/// - env value: [`AWS_ENDPOINT_URL`]
pub endpoint_url: Option<String>,
}

impl Default for Config {
Expand All @@ -118,6 +123,7 @@ impl Default for Config {
tags: None,
web_identity_token_file: None,
ec2_metadata_disabled: false,
endpoint_url: None,
}
}
}
Expand Down Expand Up @@ -163,6 +169,9 @@ impl Config {
if let Some(v) = envs.get(AWS_EC2_METADATA_DISABLED) {
self.ec2_metadata_disabled = v == "true";
}
if let Some(v) = envs.get(AWS_ENDPOINT_URL) {
self.endpoint_url = Some(v.to_string());
}
self
}

Expand Down Expand Up @@ -276,6 +285,9 @@ impl Config {
if let Some(v) = props.get("web_identity_token_file") {
self.web_identity_token_file = Some(v.to_string())
}
if let Some(v) = props.get("endpoint_url") {
self.endpoint_url = Some(v.to_string())
}

Ok(())
}
Expand Down Expand Up @@ -358,6 +370,7 @@ mod tests {
writeln!(tmp_file, "aws_access_key_id = PROFILE1ACCESSKEYID")?;
writeln!(tmp_file, "aws_secret_access_key = PROFILE1SECRETACCESSKEY")?;
writeln!(tmp_file, "aws_session_token = PROFILE1SESSIONTOKEN")?;
writeln!(tmp_file, "endpoint_url = http://localhost:8080")?;

let context = Context::new(TokioFileRead, ReqwestHttpSend::default());
let context = context.with_env(StaticEnv {
Expand All @@ -383,6 +396,10 @@ mod tests {
config.session_token,
Some("PROFILE1SESSIONTOKEN".to_owned())
);
assert_eq!(
config.endpoint_url,
Some("http://localhost:8080".to_owned())
);

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion services/aws-v4/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub const AWS_ROLE_ARN: &str = "AWS_ROLE_ARN";
pub const AWS_ROLE_SESSION_NAME: &str = "AWS_ROLE_SESSION_NAME";
pub const AWS_STS_REGIONAL_ENDPOINTS: &str = "AWS_STS_REGIONAL_ENDPOINTS";
pub const AWS_EC2_METADATA_DISABLED: &str = "AWS_EC2_METADATA_DISABLED";

pub const AWS_ENDPOINT_URL: &str = "AWS_ENDPOINT_URL";
/// AsciiSet for [AWS UriEncode](https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-header-based-auth.html)
///
/// - URI encode every byte except the unreserved characters: 'A'-'Z', 'a'-'z', '0'-'9', '-', '.', '_', and '~'.
Expand Down

0 comments on commit a69c2b6

Please sign in to comment.