Skip to content

Commit

Permalink
feat(services/s3): add role_session_name in assume roles (#4981)
Browse files Browse the repository at this point in the history
  • Loading branch information
nerdroychan authored Aug 8, 2024
1 parent d184c69 commit 0a15351
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion core/src/services/s3/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ pub struct S3Config {
pub role_arn: Option<String>,
/// external_id for this backend.
pub external_id: Option<String>,
/// role_session_name for this backend.
pub role_session_name: Option<String>,
/// Disable config load so that opendal will not load config from
/// environment.
///
Expand Down Expand Up @@ -358,6 +360,15 @@ impl S3Builder {
self
}

/// Set role_session_name for this backend.
pub fn role_session_name(mut self, v: &str) -> Self {
if !v.is_empty() {
self.config.role_session_name = Some(v.to_string())
}

self
}

/// Set default storage_class for this backend.
///
/// Available values:
Expand Down Expand Up @@ -948,13 +959,19 @@ impl Builder for S3Builder {
let default_loader = AwsDefaultLoader::new(client.client(), cfg.clone());

// Build the config for assume role.
let assume_role_cfg = AwsConfig {
let mut assume_role_cfg = AwsConfig {
region: Some(region.clone()),
role_arn: Some(role_arn),
external_id: self.config.external_id.clone(),
sts_regional_endpoints: "regional".to_string(),
..Default::default()
};

// override default role_session_name if set
if let Some(name) = self.config.role_session_name {
assume_role_cfg.role_session_name = name;
}

let assume_role_loader = AwsAssumeRoleLoader::new(
client.client(),
assume_role_cfg,
Expand Down

0 comments on commit 0a15351

Please sign in to comment.