Skip to content

Commit d004469

Browse files
committed
feat: support acct id based endpoints
1 parent a7d4950 commit d004469

27 files changed

+2041
-624
lines changed

sdk/src/Core/Amazon.Runtime/CredentialManagement/AWSCredentialsFactory.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,12 @@ private static AWSCredentials GetAWSCredentialsInternal(
205205
case CredentialProfileType.BasicWithServices:
206206
case CredentialProfileType.BasicWithGlobalEndpoint:
207207
case CredentialProfileType.BasicWithServicesAndGlobalEndpoint:
208-
return new BasicAWSCredentials(options.AccessKey, options.SecretKey);
208+
return string.IsNullOrEmpty(options.AwsAccountId) ? new BasicAWSCredentials(options.AccessKey, options.SecretKey) : new BasicAWSCredentials(options.AccessKey, options.SecretKey, options.AwsAccountId);
209209
case CredentialProfileType.Session:
210210
case CredentialProfileType.SessionWithServices:
211211
case CredentialProfileType.SessionWithGlobalEndpoint:
212212
case CredentialProfileType.SessionWithServicesAndGlobalEndpoint:
213-
return new SessionAWSCredentials(options.AccessKey, options.SecretKey, options.Token);
213+
return string.IsNullOrEmpty(options.AwsAccountId) ? new SessionAWSCredentials(options.AccessKey, options.SecretKey, options.Token) : new SessionAWSCredentials(options.AccessKey, options.SecretKey, options.Token, options.AwsAccountId); ;
214214
case CredentialProfileType.AssumeRole:
215215
case CredentialProfileType.AssumeRoleWithServices:
216216
case CredentialProfileType.AssumeRoleWithGlobalEndpoint:
@@ -353,7 +353,7 @@ private static AWSCredentials GetAWSCredentialsInternal(
353353
return ThrowOrReturnNull("Federated credentials are not available on this platform.", null, throwIfInvalid);
354354
}
355355
case CredentialProfileType.CredentialProcess:
356-
return new ProcessAWSCredentials(options.CredentialProcess);
356+
return new ProcessAWSCredentials(options.CredentialProcess, options.AwsAccountId);
357357

358358
default:
359359
var defaultMessage = profileName == null

sdk/src/Core/Amazon.Runtime/CredentialManagement/CredentialProfile.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ internal Dictionary<string, Dictionary<string, string>> NestedProperties
161161
/// </summary>
162162
public string ClientAppId { get; set; }
163163

164+
public string AwsAccountId { get; set; }
165+
164166

165167
/// <summary>
166168
/// Determines the behavior for calculating checksums for request payloads.

sdk/src/Core/Amazon.Runtime/CredentialManagement/CredentialProfileOptions.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,12 @@ public class CredentialProfileOptions
139139
/// Provided by the SSO service via the web console.
140140
/// </summary>
141141
public string SsoStartUrl { get; set; }
142-
142+
143+
/// <summary>
144+
/// The account id to use for account id based endpoint routing
145+
/// </summary>
146+
public string AwsAccountId { get; set; }
147+
143148
/// <summary>
144149
/// Return true the properties are all null or empty, false otherwise.
145150
/// </summary>
@@ -167,7 +172,8 @@ internal bool IsEmpty
167172
string.IsNullOrEmpty(SsoRoleName) &&
168173
string.IsNullOrEmpty(SsoStartUrl) &&
169174
string.IsNullOrEmpty(SsoSession) &&
170-
string.IsNullOrEmpty(WebIdentityTokenFile);
175+
string.IsNullOrEmpty(WebIdentityTokenFile) &&
176+
string.IsNullOrEmpty(AwsAccountId);
171177
}
172178
}
173179
public override string ToString()
@@ -193,6 +199,7 @@ public override string ToString()
193199
", " + "SsoRoleName=" + SsoRoleName +
194200
", " + "SsoStartUrl=" + SsoStartUrl +
195201
", " + "SsoSession=" + SsoSession +
202+
", " + "AwsAccountId=" + AwsAccountId +
196203
"]";
197204
}
198205

@@ -206,13 +213,13 @@ public override bool Equals(object obj)
206213
return false;
207214

208215
return AWSSDKUtils.AreEqual(
209-
new object[] { AccessKey, EndpointName, ExternalID, MfaSerial, RoleArn, RoleSessionName, SecretKey, SourceProfile, Token, UserIdentity, CredentialProcess, WebIdentityTokenFile, SsoAccountId, SsoRegion, SsoRegistrationScopes, SsoRoleName, SsoStartUrl, SsoSession, Services, EndpointUrl },
210-
new object[] { po.AccessKey, po.EndpointName, po.ExternalID, po.MfaSerial, po.RoleArn, po.RoleSessionName, po.SecretKey, po.SourceProfile, po.Token, po.UserIdentity, po.CredentialProcess, po.WebIdentityTokenFile, po.SsoAccountId, po.SsoRegion, po.SsoRegistrationScopes, po.SsoRoleName, po.SsoStartUrl, po.SsoSession, po.Services, po.EndpointUrl });
216+
new object[] { AccessKey, EndpointName, ExternalID, MfaSerial, RoleArn, RoleSessionName, SecretKey, SourceProfile, Token, UserIdentity, CredentialProcess, WebIdentityTokenFile, SsoAccountId, SsoRegion, SsoRegistrationScopes, SsoRoleName, SsoStartUrl, SsoSession, Services, EndpointUrl, AwsAccountId },
217+
new object[] { po.AccessKey, po.EndpointName, po.ExternalID, po.MfaSerial, po.RoleArn, po.RoleSessionName, po.SecretKey, po.SourceProfile, po.Token, po.UserIdentity, po.CredentialProcess, po.WebIdentityTokenFile, po.SsoAccountId, po.SsoRegion, po.SsoRegistrationScopes, po.SsoRoleName, po.SsoStartUrl, po.SsoSession, po.Services, po.EndpointUrl, po.AwsAccountId });
211218
}
212219

213220
public override int GetHashCode()
214221
{
215-
return Hashing.Hash(AccessKey, EndpointName, ExternalID, MfaSerial, RoleArn, RoleSessionName, SecretKey, SourceProfile, Token, UserIdentity, CredentialProcess, WebIdentityTokenFile, SsoAccountId, SsoRegion, SsoRegistrationScopes, SsoRoleName, SsoStartUrl, SsoSession, Services, EndpointUrl);
222+
return Hashing.Hash(AccessKey, EndpointName, ExternalID, MfaSerial, RoleArn, RoleSessionName, SecretKey, SourceProfile, Token, UserIdentity, CredentialProcess, WebIdentityTokenFile, SsoAccountId, SsoRegion, SsoRegistrationScopes, SsoRoleName, SsoStartUrl, SsoSession, Services, EndpointUrl, AwsAccountId);
216223
}
217224
}
218225
}

0 commit comments

Comments
 (0)