Skip to content
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

Remove obsolete endpoint logic code #3680

Merged
merged 3 commits into from
Mar 6, 2025
Merged
Changes from 1 commit
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
Next Next commit
Remove obsolete endpoint logic code
  • Loading branch information
normj committed Feb 28, 2025
commit d880ec3941c27966f0d5eaf9340e41f5703ca00b
10 changes: 10 additions & 0 deletions generator/.DevConfigs/B0756C5F-C2BC-4DBF-830C-91AC3F1359DE.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"core": {
"changeLogMessages": [
"Remove obsolete endpoint logic code",
"Remove obsolete global ClockSkew property"
],
"type": "patch",
"updateMinimum": true
}
}
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ private string GetValueSource(Parameter parameter)
{
switch (parameter.builtIn)
{
case "AWS::Region": return "config.RegionEndpoint?.SystemName";
case "AWS::Region": return "requestContext.Request.AlternateEndpoint?.SystemName ?? config.RegionEndpoint?.SystemName;";
Copy link
Contributor

@dscpinheiro dscpinheiro Mar 6, 2025

Choose a reason for hiding this comment

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

There's an extra ; here, I ran the generator and the resolvers ended up with ;; at the end:

result.Region = requestContext.Request.AlternateEndpoint?.SystemName ?? config.RegionEndpoint?.SystemName;;

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed the extra ;

case "AWS::UseFIPS": return "config.UseFIPSEndpoint";
case "AWS::UseDualStack": return "config.UseDualstackEndpoint";
case "SDK::Endpoint": return "config.ServiceURL";

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -135,6 +135,9 @@ namespace <#=this.Config.Namespace#>
ClientConfig = this,
OriginalRequest = parameters.Request,
Request = new DefaultRequest(parameters.Request, ServiceId)
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Not related to this PR, but what's the use case for AlternateEndpoint? I did not know about it and even had to double check it wasn't added in the PR.

Copy link
Member Author

@normj normj Mar 6, 2025

Choose a reason for hiding this comment

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

It is being used in scenarios like RDS and DocDB where they support copying a database from a different region. This code path is getting triggered by the changes PreSignedUrlRequestHandler.cs classes. We essentially have to create a presigned URL to the resource in the region the database is being copied. So we need use the current client config settings but override the region with the region the database is in.

In V3 the URL for the presigned URL was being generated by the old obsolete method that didn't use EP 2.0.

AlternateEndpoint = parameters.AlternateEndpoint
}
};

var executionContext = new Amazon.Runtime.Internal.ExecutionContext(requestContext, null);
20 changes: 0 additions & 20 deletions sdk/src/Core/AWSConfigs.cs
Original file line number Diff line number Diff line change
@@ -123,33 +123,13 @@ public static TimeSpan? ManualClockCorrection
/// by determining the correct server time and reissuing the
/// request with the correct time.
/// Default value of this field is True.
/// <seealso cref="ClockOffset"/> will be updated with the calculated
/// offset even if this field is set to false, though requests
/// will not be corrected or retried.
/// Ignored if <seealso cref="ManualClockCorrection"/> is set.
/// </summary>
public static bool CorrectForClockSkew
{
get { return _rootConfig.CorrectForClockSkew; }
set { _rootConfig.CorrectForClockSkew = value; }
}

/// <summary>
/// The calculated clock skew correction, if there is one.
/// This field will be set if a service call resulted in an exception
/// and the SDK has determined that there is a difference between local
/// and server times.
///
/// If <seealso cref="CorrectForClockSkew"/> is set to true, this
/// value will be set to the correction, but it will not be used by the
/// SDK and clock skew errors will not be retried.
/// </summary>
[Obsolete("This value is deprecated in favor of IClientConfig.ClockOffset, use CorrectClockSkew.GetClockCorrectionForEndpoint(string endpoint) instead.")]
public static TimeSpan ClockOffset
{
get;
internal set;
}
#endregion

#region Region
26 changes: 0 additions & 26 deletions sdk/src/Core/Amazon.Runtime/ClientConfig.cs
Original file line number Diff line number Diff line change
@@ -19,8 +19,6 @@


using Amazon.Util;
using System.Globalization;
using Amazon.Internal;
using Amazon.Runtime.Endpoints;
using Amazon.Runtime.Internal;
using Amazon.Runtime.Internal.Util;
@@ -397,18 +395,6 @@ public bool UseHttp
set { this.useHttp = value; }
}

internal static string GetUrl(IClientConfig config, RegionEndpoint regionEndpoint)
{
#pragma warning disable CS0612,CS0618
var endpoint =
regionEndpoint.GetEndpointForService(
config.RegionEndpointServiceName,
config.ToGetEndpointForServiceOptions());
#pragma warning restore CS0612,CS0618
string url = new Uri(string.Format(CultureInfo.InvariantCulture, "{0}{1}", config.UseHttp ? "http://" : "https://", endpoint.Hostname)).AbsoluteUri;
return url;
}

/// <summary>
/// Gets and sets the AuthenticationRegion property.
/// Used in AWS4 request signing, this is an optional property;
@@ -938,18 +924,6 @@ public virtual void Validate()
#endif
}

/// <summary>
/// Wrapper around <seealso cref="AWSConfigs.ManualClockCorrection"/>
/// </summary>
[Obsolete("Please use CorrectClockSkew.GetClockCorrectionForEndpoint(string endpoint) instead.", false)]
public TimeSpan ClockOffset
{
get
{
return AWSConfigs.ManualClockCorrection.GetValueOrDefault();
}
}

/// <summary>
/// Gets and sets the DisableHostPrefixInjection flag. If true, host prefix injection will be disabled for this client, the default value of this flag is false.
/// Host prefix injection prefixes the service endpoint with request members from APIs which use this feature.
3 changes: 0 additions & 3 deletions sdk/src/Core/Amazon.Runtime/CorrectClockSkew.cs
Original file line number Diff line number Diff line change
@@ -127,9 +127,6 @@ internal static void SetClockCorrectionForEndpoint(string endpoint, TimeSpan cor
try
{
clockCorrectionDictionary[endpoint] = correction;
#pragma warning disable CS0618 // Type or member is obsolete
AWSConfigs.ClockOffset = correction;
#pragma warning restore CS0618 // Type or member is obsolete
}
finally
{
Original file line number Diff line number Diff line change
@@ -51,28 +51,6 @@ protected static string GetContents(Uri uri, IWebProxy proxy, Dictionary<string,
}
}

[Obsolete("This method is not compatible with Native AOT builds. The GetObjectFromResponse overload using the generic parameter taking in a JsonSerializerContext should be used instead.")]
[RequiresUnreferencedCode("GetObjectFromResponse overload using the generic parameter taking in a JsonSerializerContext should be used instead.")]
protected static T GetObjectFromResponse<T>(Uri uri)
{
return GetObjectFromResponse<T>(uri, null, null);
}

[Obsolete("This method is not compatible with Native AOT builds. The GetObjectFromResponse overload using the generic parameter taking in a JsonSerializerContext should be used instead.")]
[RequiresUnreferencedCode("GetObjectFromResponse overload using the generic parameter taking in a JsonSerializerContext should be used instead.")]
protected static T GetObjectFromResponse<T>(Uri uri, IWebProxy proxy)
{
return GetObjectFromResponse<T>(uri, proxy, null);
}

[Obsolete("This method is not compatible with Native AOT builds. The GetObjectFromResponse overload using the generic parameter taking in a JsonSerializerContext should be used instead.")]
[RequiresUnreferencedCode("GetObjectFromResponse overload using the generic parameter taking in a JsonSerializerContext should be used instead.")]
protected static T GetObjectFromResponse<T>(Uri uri, IWebProxy proxy, Dictionary<string, string> headers)
{
string json = GetContents(uri, proxy, headers);
return JsonSerializer.Deserialize<T>(json);
}

protected static T GetObjectFromResponse<T, TC>(Uri uri, IWebProxy proxy, Dictionary<string, string> headers)
where TC :
#if NET8_0_OR_GREATER
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
*/
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace Amazon.Runtime.Endpoints
{
@@ -27,9 +28,20 @@ public ServiceOperationEndpointParameters(AmazonWebServiceRequest request)
Request = request;
}

public ServiceOperationEndpointParameters(AmazonWebServiceRequest request, RegionEndpoint alternateEndpoint)
: this(request)
{
AlternateEndpoint = alternateEndpoint;
}

/// <summary>
/// Request for the desired service operation.
/// </summary>
public AmazonWebServiceRequest Request { get; }

/// <summary>
/// Alternate endpoint that overrides the endpoint configured for service client.
/// </summary>
public RegionEndpoint AlternateEndpoint { get; }
}
}
5 changes: 0 additions & 5 deletions sdk/src/Core/Amazon.Runtime/IClientConfig.cs
Original file line number Diff line number Diff line change
@@ -288,11 +288,6 @@ public partial interface IClientConfig
/// <exception cref="Amazon.Runtime.AmazonClientException">The timeout specified is null.</exception>
void Validate();

/// <summary>
/// Returns the calculated clock skew value for this config's service endpoint. If AWSConfigs.CorrectForClockSkew is false,
/// this value won't be used to construct service requests.
/// </summary>
TimeSpan ClockOffset { get; }
/// <summary>
/// Gets the DisableHostPrefixInjection flag. If true, host prefix injection will be disabled for this client, the default value of this flag is false.
/// Host prefix injection prefixes the service endpoint with request members from APIs which use this feature.
17 changes: 0 additions & 17 deletions sdk/src/Core/Amazon.Runtime/Internal/Auth/AWS4Signer.cs
Original file line number Diff line number Diff line change
@@ -18,7 +18,6 @@
using System.Linq;
using System.Text;
using System.Globalization;
using Amazon.Internal;
using Amazon.Util;
using Amazon.Runtime.Internal.Util;
using Amazon.Runtime.Endpoints;
@@ -663,12 +662,6 @@ public static string DetermineSigningRegion(IClientConfig clientConfig,
// client config properties.
if (alternateEndpoint != null)
{
#pragma warning disable CS0612,CS0618
var serviceEndpoint = alternateEndpoint.GetEndpointForService(serviceName, clientConfig.ToGetEndpointForServiceOptions());
#pragma warning restore CS0612,CS0618
if (serviceEndpoint.AuthRegion != null)
Copy link
Member Author

Choose a reason for hiding this comment

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

It was safe to remove the serviceEndpoint.AuthRegion != null check because the endpoint returned from GetEndpointForService sets the auth region to null.

return serviceEndpoint.AuthRegion;

return alternateEndpoint.SystemName;
}

@@ -694,16 +687,6 @@ public static string DetermineSigningRegion(IClientConfig clientConfig,
var endpoint = clientConfig.RegionEndpoint;
if (endpoint != null)
{
#pragma warning disable CS0612,CS0618
var serviceEndpoint = endpoint.GetEndpointForService(serviceName, clientConfig.ToGetEndpointForServiceOptions());
if (!string.IsNullOrEmpty(serviceEndpoint.AuthRegion))
Copy link
Member Author

Choose a reason for hiding this comment

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

It was safe to remove the serviceEndpoint.AuthRegion != null check because the endpoint returned from GetEndpointForService sets the auth region to null.

return serviceEndpoint.AuthRegion;

// Check if the region is overridden in the endpoints.json file
var overrideRegion = RegionEndpoint.GetRegionEndpointOverride(endpoint);
if (overrideRegion != null)
return overrideRegion.SystemName;
#pragma warning restore CS0612,CS0618
return endpoint.SystemName;
}

Original file line number Diff line number Diff line change
@@ -13,14 +13,8 @@
* permissions and limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
#if AWS_ASYNC_API
using System.Threading;
using System.Threading.Tasks;
#endif
using Amazon.Internal;
using Amazon.Util;
using Amazon.Runtime.Internal.Util;

Original file line number Diff line number Diff line change
@@ -76,10 +76,8 @@ public virtual Uri DetermineEndpoint(IRequestContext requestContext)

public static Uri DetermineEndpoint(IClientConfig config, IRequest request)
{
Uri endpoint = request.AlternateEndpoint != null
? new Uri(ClientConfig.GetUrl(config, request.AlternateEndpoint))
: new Uri(config.DetermineServiceOperationEndpoint(
new ServiceOperationEndpointParameters(request.OriginalRequest)).URL);
Uri endpoint = new Uri(config.DetermineServiceOperationEndpoint(
Copy link
Member Author

Choose a reason for hiding this comment

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

I was able to get rid of the GetUrl call because I updated DetermineServiceOperationEndpoint to take in an alternate endpoint.

new ServiceOperationEndpointParameters(request.OriginalRequest, request.AlternateEndpoint)).URL);

return InjectHostPrefix(config, request, endpoint);
}
Original file line number Diff line number Diff line change
@@ -452,7 +452,7 @@ private bool IsClockskew(IExecutionContext executionContext, Exception exception
if (isDefiniteClockSkewErrorCode && serverTimeDetermined)
{
Logger.InfoFormat(clockSkewMessageFormat,
realNow, correctedNow, clientConfig.ClockOffset, serverTime, endpoint);
realNow, correctedNow, CorrectClockSkew.GetCorrectedUtcNowForEndpoint(endpoint), serverTime, endpoint);
var newCorrection = serverTime - realNow;
CorrectClockSkew.SetClockCorrectionForEndpoint(endpoint, newCorrection);
if (shouldRetry)
23 changes: 1 addition & 22 deletions sdk/src/Core/Amazon.Util/AWSSDKUtils.cs
Original file line number Diff line number Diff line change
@@ -480,28 +480,7 @@ public static IEnumerable<UriComponent> SplitResourcePathIntoSegmentsV2(string r

return uriComponentSegments;
}

/// <summary>
/// Joins all path segments with the / character and encodes each segment before joining.
/// </summary>
/// <param name="pathSegments">The segments of a URL path split at each / character</param>
/// <param name="path">If the path property is specified,
/// the accepted path characters {/+:} are not encoded.</param>
/// <returns>A joined URL with encoded segments</returns>
[Obsolete("This method has been deprecated due to an issue with not encoding special characters. Use JoinResourcePathSegmentsV2 instead.")]
public static string JoinResourcePathSegments(IEnumerable<string> pathSegments, bool path)
{
// Encode for canonicalization
pathSegments = pathSegments.Select(segment => UrlEncode(segment, path));

if (path)
{
pathSegments = pathSegments.Select(segment => segment.Replace(Slash, EncodedSlash));
}

// join the encoded segments with /
return string.Join(Slash, pathSegments.ToArray());
}

/// <summary>
/// Joins all path segments with the / character and encodes each segment before joining
/// </summary>
33 changes: 0 additions & 33 deletions sdk/src/Core/Amazon.Util/Internal/InternalSDKUtils.cs
Original file line number Diff line number Diff line change
@@ -144,39 +144,6 @@ public static string BuildUserAgentString(string serviceId, string serviceSdkVer
}

#endregion
[Obsolete("This method is not AOT safe and is no longer used in the SDK. Please use ApplyValuesV2 for AOT compatibility. This method is left here for backwards compatibility purposes")]
public static void ApplyValues(object target, IDictionary<string, object> propertyValues)
{
if (propertyValues == null || propertyValues.Count == 0)
return;

var targetType = target.GetType();

foreach(var kvp in propertyValues)
{
var property = targetType.GetProperty(kvp.Key);
if (property == null)
throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Unable to find property {0} on type {1}.", kvp.Key, targetType.FullName));

try
{
var propertyTypeInfo = property.PropertyType;
if (propertyTypeInfo.IsEnum)
{
var enumValue = Enum.Parse(propertyTypeInfo, kvp.Value.ToString(), true);
property.SetValue(target, enumValue, null);
}
else
{
property.SetValue(target, kvp.Value, null);
}
}
catch(Exception e)
{
throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Unable to set property {0} on type {1}: {2}", kvp.Key, targetType.FullName, e.Message));
}
}
}

public static void ApplyValuesV2<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T>(T target, IDictionary<string, object> propertyValues)
{
8 changes: 3 additions & 5 deletions sdk/src/Core/Amazon.Util/Internal/RegionFinder.cs
Original file line number Diff line number Diff line change
@@ -17,15 +17,13 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Amazon.Internal;
using Amazon.Runtime.Internal.Util;

namespace Amazon.Util.Internal
{
/// <summary>
/// Finds region string in the endpoint string using predefined rules
/// If predefined rules fail to match the region, regular expression strings provided in
/// endpoints.json are used to find the region.
/// If predefined rules fail to match the region, regular expression are used to find the region.
/// If regular expressions also fail, then a default region is returned.
/// </summary>
public class RegionFinder
@@ -67,7 +65,7 @@ internal RegionFinder()

/// <summary>
/// Finds the region in the provided endpoint parsing from right to left
/// Try to find exact match of the region in endpoints.json
/// Try to find exact match of the region from the SDK's known regions.
/// If there doesn't exist an exact match, find a fuzzy match
/// Else return default region
/// </summary>
@@ -131,7 +129,7 @@ public static string GetAuthority(string url)
}

/// <summary>
/// Find region in the endpoint using endpoints.json region regexs
/// Find region in the endpoint using regexs
/// If there doesn't exist a match, return null
/// </summary>
/// <param name="endpoint"></param>
Loading
Oops, something went wrong.