Skip to content

Commit

Permalink
Make InternalSDKUtils AOT compatible in V4 (#3516)
Browse files Browse the repository at this point in the history
* fix #3497. Make InternalSDKUtils aot compatible in v4
  • Loading branch information
peterrsongg authored Oct 17, 2024
1 parent a0f7453 commit 5de9e0e
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"core": {
"changeLogMessages": [
"Fix #3497, make InternalSDKUtils aot compatible in V4."
],
"type": "patch",
"updateMinimum": true
}
}
10 changes: 7 additions & 3 deletions sdk/src/Core/Amazon.Util/Internal/InternalSDKUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using Amazon.Runtime.Internal.Util;
using Amazon.Util.Internal.PlatformServices;
using System.Text;
using System.Diagnostics.CodeAnalysis;

namespace Amazon.Util.Internal
{
Expand Down Expand Up @@ -142,13 +143,16 @@ public static string BuildUserAgentString(string serviceId, string serviceSdkVer
}

#endregion

public static void ApplyValues(object target, IDictionary<string, object> propertyValues)
#if NET8_0_OR_GREATER
public static void ApplyValuesV2<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>(T target, IDictionary<string, object> propertyValues)
#else
public static void ApplyValuesV2<T>(T target, IDictionary<string, object> propertyValues)
#endif
{
if (propertyValues == null || propertyValues.Count == 0)
return;

var targetType = target.GetType();
var targetType = typeof(T);

foreach(var kvp in propertyValues)
{
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/Services/S3/Custom/AmazonS3Client.Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ string ICoreAmazonS3.GeneratePreSignedURL(string bucketName, string objectKey, D
Key = objectKey,
Expires = expiration
};
InternalSDKUtils.ApplyValues(request, additionalProperties);
InternalSDKUtils.ApplyValuesV2(request, additionalProperties);


return this.GetPreSignedURL(request);
Expand Down
14 changes: 7 additions & 7 deletions sdk/src/Services/S3/Custom/_async/AmazonS3Client.Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async Task<IList<string>> ICoreAmazonS3.GetAllObjectKeysAsync(string bucketName,
Prefix = prefix,
Marker = marker
};
InternalSDKUtils.ApplyValues(request, additionalProperties);
InternalSDKUtils.ApplyValuesV2(request, additionalProperties);

var listResponse = await this.ListObjectsAsync(request).ConfigureAwait(false);
if (listResponse.S3Objects != null)
Expand All @@ -61,7 +61,7 @@ Task ICoreAmazonS3.DeleteAsync(string bucketName, string objectKey, IDictionary<
BucketName = bucketName,
Key = objectKey
};
InternalSDKUtils.ApplyValues(request, additionalProperties);
InternalSDKUtils.ApplyValuesV2(request, additionalProperties);
return this.DeleteObjectAsync(request, cancellationToken);
}

Expand All @@ -76,7 +76,7 @@ Task ICoreAmazonS3.DeletesAsync(string bucketName, IEnumerable<string> objectKey
{
request.AddKey(key);
}
InternalSDKUtils.ApplyValues(request, additionalProperties);
InternalSDKUtils.ApplyValuesV2(request, additionalProperties);
return this.DeleteObjectsAsync(request, cancellationToken);
}

Expand All @@ -89,7 +89,7 @@ Task ICoreAmazonS3.UploadObjectFromStreamAsync(string bucketName, string objectK
Key = objectKey,
InputStream = stream
};
InternalSDKUtils.ApplyValues(request, additionalProperties);
InternalSDKUtils.ApplyValuesV2(request, additionalProperties);
return transfer.UploadAsync(request, cancellationToken);
}

Expand All @@ -100,7 +100,7 @@ async Task<Stream> ICoreAmazonS3.GetObjectStreamAsync(string bucketName, string
BucketName = bucketName,
Key = objectKey
};
InternalSDKUtils.ApplyValues(request, additionalProperties);
InternalSDKUtils.ApplyValuesV2(request, additionalProperties);

return (await this.GetObjectAsync(request, cancellationToken).ConfigureAwait(false)).ResponseStream;
}
Expand All @@ -114,7 +114,7 @@ Task ICoreAmazonS3.UploadObjectFromFilePathAsync(string bucketName, string objec
Key = objectKey,
FilePath = filepath
};
InternalSDKUtils.ApplyValues(request, additionalProperties);
InternalSDKUtils.ApplyValuesV2(request, additionalProperties);

return transfer.UploadAsync(request, cancellationToken);
}
Expand All @@ -129,7 +129,7 @@ Task ICoreAmazonS3.DownloadToFilePathAsync(string bucketName, string objectKey,
Key = objectKey,
FilePath = filepath
};
InternalSDKUtils.ApplyValues(request, additionalProperties);
InternalSDKUtils.ApplyValuesV2(request, additionalProperties);

return transfer.DownloadAsync(request, cancellationToken);
}
Expand Down
14 changes: 7 additions & 7 deletions sdk/src/Services/S3/Custom/_bcl/AmazonS3Client.Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ IList<string> ICoreAmazonS3.GetAllObjectKeys(string bucketName, string prefix, I
Prefix = prefix,
Marker = marker
};
InternalSDKUtils.ApplyValues(request, additionalProperties);
InternalSDKUtils.ApplyValuesV2(request, additionalProperties);

var listResponse = this.ListObjects(request);
if (listResponse.S3Objects != null)
Expand All @@ -60,7 +60,7 @@ void ICoreAmazonS3.Delete(string bucketName, string objectKey, IDictionary<strin
BucketName = bucketName,
Key = objectKey
};
InternalSDKUtils.ApplyValues(request, additionalProperties);
InternalSDKUtils.ApplyValuesV2(request, additionalProperties);
this.DeleteObject(request);
}

Expand All @@ -75,7 +75,7 @@ void ICoreAmazonS3.Deletes(string bucketName, IEnumerable<string> objectKeys, ID
{
request.AddKey(key);
}
InternalSDKUtils.ApplyValues(request, additionalProperties);
InternalSDKUtils.ApplyValuesV2(request, additionalProperties);
this.DeleteObjects(request);
}

Expand All @@ -88,7 +88,7 @@ void ICoreAmazonS3.UploadObjectFromStream(string bucketName, string objectKey, S
Key = objectKey,
InputStream = stream
};
InternalSDKUtils.ApplyValues(request, additionalProperties);
InternalSDKUtils.ApplyValuesV2(request, additionalProperties);
transfer.Upload(request);
}

Expand All @@ -101,7 +101,7 @@ void ICoreAmazonS3.UploadObjectFromFilePath(string bucketName, string objectKey,
Key = objectKey,
FilePath = filepath
};
InternalSDKUtils.ApplyValues(request, additionalProperties);
InternalSDKUtils.ApplyValuesV2(request, additionalProperties);
transfer.Upload(request);
}

Expand All @@ -115,7 +115,7 @@ void ICoreAmazonS3.DownloadToFilePath(string bucketName, string objectKey, strin
Key = objectKey,
FilePath = filepath
};
InternalSDKUtils.ApplyValues(request, additionalProperties);
InternalSDKUtils.ApplyValuesV2(request, additionalProperties);
transfer.Download(request);
}

Expand All @@ -126,7 +126,7 @@ Stream ICoreAmazonS3.GetObjectStream(string bucketName, string objectKey, IDicti
BucketName = bucketName,
Key = objectKey
};
InternalSDKUtils.ApplyValues(request, additionalProperties);
InternalSDKUtils.ApplyValuesV2(request, additionalProperties);
return this.GetObject(request).ResponseStream;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static ImmutableCredentials CredentialsFromSsoAccessToken(IAmazonSSO clie
AccountId = accountId,
RoleName = roleName,
};
InternalSDKUtils.ApplyValues(request, additionalProperties);
InternalSDKUtils.ApplyValuesV2(request, additionalProperties);

var response = client.GetRoleCredentials(request);

Expand Down Expand Up @@ -94,7 +94,7 @@ public static async Task<ImmutableCredentials> CredentialsFromSsoAccessTokenAsyn
AccountId = accountId,
RoleName = roleName,
};
InternalSDKUtils.ApplyValues(request, additionalProperties);
InternalSDKUtils.ApplyValuesV2(request, additionalProperties);

var response = await client.GetRoleCredentialsAsync(request).ConfigureAwait(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public static GetSsoTokenResponse GetSsoToken(IAmazonSSOOIDC client, GetSsoToken
registerClientRequest.RedirectUris = new List<string> { request.PkceFlowOptions.RedirectUri };
}

InternalSDKUtils.ApplyValues(registerClientRequest, request.AdditionalProperties);
InternalSDKUtils.ApplyValuesV2(registerClientRequest, request.AdditionalProperties);
var registerClientResponse = client.RegisterClient(registerClientRequest);

if (useDeviceCodeFlow)
Expand All @@ -112,7 +112,7 @@ public static GetSsoTokenResponse GetSsoToken(IAmazonSSOOIDC client, GetSsoToken
ClientId = registerClientResponse.ClientId,
StartUrl = request.StartUrl,
};
InternalSDKUtils.ApplyValues(startDeviceAuthorizationRequest, request.AdditionalProperties);
InternalSDKUtils.ApplyValuesV2(startDeviceAuthorizationRequest, request.AdditionalProperties);

var startDeviceAuthorizationResponse = client.StartDeviceAuthorization(startDeviceAuthorizationRequest);

Expand All @@ -134,7 +134,7 @@ public static GetSsoTokenResponse GetSsoToken(IAmazonSSOOIDC client, GetSsoToken
GrantType = CreateTokenDefaultGrantType,
DeviceCode = startDeviceAuthorizationResponse.DeviceCode,
};
InternalSDKUtils.ApplyValues(createTokenRequest, request.AdditionalProperties);
InternalSDKUtils.ApplyValuesV2(createTokenRequest, request.AdditionalProperties);

createTokenResponse = PollForSsoToken(client, createTokenRequest, startDeviceAuthorizationResponse.Interval.Value, deviceCodeExpiration, context);
}
Expand All @@ -157,7 +157,7 @@ public static GetSsoTokenResponse GetSsoToken(IAmazonSSOOIDC client, GetSsoToken
Code = authorizationCode,
CodeVerifier = codeVerifier,
};
InternalSDKUtils.ApplyValues(createTokenRequest, request.AdditionalProperties);
InternalSDKUtils.ApplyValuesV2(createTokenRequest, request.AdditionalProperties);

createTokenResponse = client.CreateToken(createTokenRequest);
}
Expand Down Expand Up @@ -256,7 +256,7 @@ public static async Task<GetSsoTokenResponse> GetSsoTokenAsync(IAmazonSSOOIDC cl
registerClientRequest.RedirectUris = new List<string> { request.PkceFlowOptions.RedirectUri };
}

InternalSDKUtils.ApplyValues(registerClientRequest, request.AdditionalProperties);
InternalSDKUtils.ApplyValuesV2(registerClientRequest, request.AdditionalProperties);
var registerClientResponse = await client.RegisterClientAsync(registerClientRequest, cancellationToken).ConfigureAwait(false);

if (useDeviceCodeFlow)
Expand All @@ -267,7 +267,7 @@ public static async Task<GetSsoTokenResponse> GetSsoTokenAsync(IAmazonSSOOIDC cl
ClientId = registerClientResponse.ClientId,
StartUrl = request.StartUrl,
};
InternalSDKUtils.ApplyValues(startDeviceAuthorizationRequest, request.AdditionalProperties);
InternalSDKUtils.ApplyValuesV2(startDeviceAuthorizationRequest, request.AdditionalProperties);

var startDeviceAuthorizationResponse =
await client.StartDeviceAuthorizationAsync(startDeviceAuthorizationRequest, cancellationToken).ConfigureAwait(false);
Expand All @@ -290,7 +290,7 @@ public static async Task<GetSsoTokenResponse> GetSsoTokenAsync(IAmazonSSOOIDC cl
GrantType = CreateTokenDefaultGrantType,
DeviceCode = startDeviceAuthorizationResponse.DeviceCode,
};
InternalSDKUtils.ApplyValues(createTokenRequest, request.AdditionalProperties);
InternalSDKUtils.ApplyValuesV2(createTokenRequest, request.AdditionalProperties);

createTokenResponse = await PollForSsoTokenAsync(
client,
Expand Down Expand Up @@ -323,7 +323,7 @@ public static async Task<GetSsoTokenResponse> GetSsoTokenAsync(IAmazonSSOOIDC cl
Code = authorizationCode,
CodeVerifier = codeVerifier,
};
InternalSDKUtils.ApplyValues(createTokenRequest, request.AdditionalProperties);
InternalSDKUtils.ApplyValuesV2(createTokenRequest, request.AdditionalProperties);

createTokenResponse = await client.CreateTokenAsync(createTokenRequest, cancellationToken).ConfigureAwait(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void SetHttpVerb()
var request = new GetPreSignedUrlRequest();
var values = new Dictionary<string, object> { { "Verb", "DELETE" } };

InternalSDKUtils.ApplyValues(request, values);
InternalSDKUtils.ApplyValuesV2(request, values);

Assert.AreEqual(request.Verb, HttpVerb.DELETE);
}
Expand All @@ -40,14 +40,14 @@ public void SetAutoCloseStream()
var request = new PutObjectRequest();
var values = new Dictionary<string, object> { { "AutoCloseStream", false } };

InternalSDKUtils.ApplyValues(request, values);
InternalSDKUtils.ApplyValuesV2(request, values);

Assert.AreEqual(request.AutoCloseStream, false);

request = new PutObjectRequest();
values = new Dictionary<string, object> { { "AutoCloseStream", true } };

InternalSDKUtils.ApplyValues(request, values);
InternalSDKUtils.ApplyValuesV2(request, values);

Assert.AreEqual(request.AutoCloseStream, true);
}
Expand Down

0 comments on commit 5de9e0e

Please sign in to comment.