Skip to content

Avoid cloning ImmutableCredentials objects. #3936

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 31, 2025
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
32 changes: 32 additions & 0 deletions generator/.DevConfigs/efb0dd6a-3af3-4c38-a7d1-9188ccd1bf39.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"core": {
"updateMinimum": false,
"type": "patch",
"changeLogMessages": [
"Avoid cloning \u0060ImmutableCredentials\u0060 objects."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not positive if our build system will accept \u0060 but I will dry run this PR to determine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DRY_RUN-c6382969-8690-4729-a359-43bb125eb338 started

]
},
"services": [
{
"serviceName": "GameLift",
"type": "patch",
"changeLogMessages": [
"Avoid cloning \u0060ImmutableCredentials\u0060 objects."
]
},
{
"serviceName": "SecurityToken",
"type": "patch",
"changeLogMessages": [
"Avoid cloning \u0060ImmutableCredentials\u0060 objects."
]
},
{
"serviceName": "CognitoIdentity",
"type": "patch",
"changeLogMessages": [
"Avoid cloning \u0060ImmutableCredentials\u0060 objects."
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,7 @@ public BasicAWSCredentials(string accessKey, string secretKey, string accountId)
/// <returns></returns>
public override ImmutableCredentials GetCredentials()
{
if (this._credentials == null)
return null;

return _credentials.Copy();
return _credentials;
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public override ImmutableCredentials GetCredentials()
_imdsRefreshFailed = false;
}

return _lastRetrievedCredentials?.Credentials.Copy();
return _lastRetrievedCredentials?.Credentials;
}
}
finally
Expand Down Expand Up @@ -161,7 +161,7 @@ public override ImmutableCredentials GetCredentials()
_imdsRefreshFailed = false;
}

credentials = _lastRetrievedCredentials.Credentials?.Copy();
credentials = _lastRetrievedCredentials.Credentials;
}
finally
{
Expand Down Expand Up @@ -211,7 +211,7 @@ public override async Task<ImmutableCredentials> GetCredentialsAsync()
_imdsRefreshFailed = false;
}

return _lastRetrievedCredentials?.Credentials.Copy();
return _lastRetrievedCredentials?.Credentials;
}
}
finally
Expand Down Expand Up @@ -250,7 +250,7 @@ public override async Task<ImmutableCredentials> GetCredentialsAsync()
_imdsRefreshFailed = false;
}

credentials = _lastRetrievedCredentials.Credentials?.Copy();
credentials = _lastRetrievedCredentials.Credentials;
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ protected override CredentialsRefreshState GenerateNewCredentials()
var newExpiryTime = AWSSDKUtils.CorrectedUtcNow + TimeSpan.FromMinutes(2);
#pragma warning restore CS0612,CS0618 // Type or member is obsolete

_currentRefreshState = new CredentialsRefreshState(_currentRefreshState.Credentials.Copy(), newExpiryTime);
_currentRefreshState = new CredentialsRefreshState(_currentRefreshState.Credentials, newExpiryTime);
return _currentRefreshState;
}
}
Expand All @@ -111,7 +111,7 @@ protected override CredentialsRefreshState GenerateNewCredentials()
var newExpiryTime = AWSSDKUtils.CorrectedUtcNow + TimeSpan.FromMinutes(new Random().Next(5, 11));
#pragma warning restore CS0612, CS0618 // Type or member is obsolete

_currentRefreshState = new CredentialsRefreshState(newState.Credentials.Copy(), newExpiryTime);
_currentRefreshState = new CredentialsRefreshState(newState.Credentials, newExpiryTime);

return _currentRefreshState;
}
Expand Down Expand Up @@ -176,7 +176,7 @@ protected override async Task<CredentialsRefreshState> GenerateNewCredentialsAsy
if (null != _currentRefreshState)
{
var newExpiryTime = AWSSDKUtils.CorrectedUtcNow + TimeSpan.FromMinutes(2);
_currentRefreshState = new CredentialsRefreshState(_currentRefreshState.Credentials.Copy(), newExpiryTime);
_currentRefreshState = new CredentialsRefreshState(_currentRefreshState.Credentials, newExpiryTime);
return _currentRefreshState;
}
}
Expand All @@ -188,7 +188,7 @@ protected override async Task<CredentialsRefreshState> GenerateNewCredentialsAsy

// use a custom refresh time
var newExpiryTime = AWSSDKUtils.CorrectedUtcNow + TimeSpan.FromMinutes(new Random().Next(5, 11));
_currentRefreshState = new CredentialsRefreshState(newState.Credentials.Copy(), newExpiryTime);
_currentRefreshState = new CredentialsRefreshState(newState.Credentials, newExpiryTime);

return _currentRefreshState;
}
Expand Down Expand Up @@ -402,7 +402,7 @@ private CredentialsRefreshState GetEarlyRefreshState(CredentialsRefreshState sta
if (newExpiryTime > state.Expiration)
newExpiryTime = state.Expiration;

return new CredentialsRefreshState(state.Credentials.Copy(), newExpiryTime);
return new CredentialsRefreshState(state.Credentials, newExpiryTime);
}

private CredentialsRefreshState GetRefreshState(string token)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public override sealed ImmutableCredentials GetCredentials()
tempState = GenerateCredentialsAndUpdateState();
}

return tempState.Credentials.Copy();
return tempState.Credentials;

CredentialsRefreshState GenerateCredentialsAndUpdateState()
{
Expand Down Expand Up @@ -202,7 +202,7 @@ public override sealed async System.Threading.Tasks.Task<ImmutableCredentials> G
tempState = await GenerateCredentialsAndUpdateStateAsync().ConfigureAwait(false);
}

return tempState.Credentials.Copy();
return tempState.Credentials;

async System.Threading.Tasks.Task<CredentialsRefreshState> GenerateCredentialsAndUpdateStateAsync()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public SessionAWSCredentials(string awsAccessKeyId, string awsSecretAccessKey, s
/// <returns></returns>
public override ImmutableCredentials GetCredentials()
{
return _lastCredentials.Copy();
return _lastCredentials;
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public override ImmutableCredentials GetCredentials()
{
if (_credentials == null)
_credentials = new ImmutableCredentials(AccessKeyId, SecretKey, SessionToken);
return _credentials.Copy();
return _credentials;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public override ImmutableCredentials GetCredentials()
{
if (_credentials == null)
_credentials = new ImmutableCredentials(AccessKeyId, SecretAccessKey, SessionToken);
return _credentials.Copy();
return _credentials;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public override ImmutableCredentials GetCredentials()
{
if (_credentials == null)
_credentials = new ImmutableCredentials(AccessKeyId, SecretAccessKey, SessionToken);
return _credentials.Copy();
return _credentials;
}
}
}