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

Conversation

normj
Copy link
Member

@normj normj commented Feb 28, 2025

Description

As part of doing a sweep for obsolete code that should be removed for V4 this PR removes all of the obsolete code from Core except for the obsolete on the ReadWriteTimeout. I want to do that as a separate PR.

The main chuck of the code that was removed was old endpoint code when we relied on endpoints.json. The main reason the old endpoint logic was being used where an endpoint needed to computed with an alternate endpoint. Generally a presigned url use case copying a resource from another region. I update the endpoints 2.0 code to allow overriding the region with an alternate endpoint. This required a small generator change. In the PR I only included a few of the generated results that I needed to address tests and give an example of what the change will look like.

Testing

Dry run: DRY_RUN-eee71360-5560-4668-90fb-ddd8e052c3f0 Successful

@normj normj added the v4 label Feb 28, 2025
#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.

@@ -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.

? 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.

@@ -98,7 +97,7 @@ protected virtual void PreInvoke(IExecutionContext executionContext)
var iRequest = marshaller.Marshall(preSignedUrlRequest as AmazonWebServiceRequest);
iRequest.UseQueryString = true;
iRequest.HttpMethod = HTTPGet;
iRequest.Endpoint = new UriBuilder(UriSchemeHTTPS, endpoint.GetEndpointForService(config).Hostname).Uri;
iRequest.Endpoint = new Uri(config.DetermineServiceOperationEndpoint(new Runtime.Endpoints.ServiceOperationEndpointParameters(executionContext.RequestContext.OriginalRequest, RegionEndpoint.GetBySystemName(preSignedUrlRequest.SourceRegion))).URL);
Copy link
Member Author

Choose a reason for hiding this comment

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

This is using the new logic I added for the endpoints 2.0 code path allowing to pass in an alternate endpoint. In that case the source region of the resource being copied. This same logic is done in other services that have a copy feature like RDS and Neptune.

@@ -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 ;

@@ -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.

@dscpinheiro dscpinheiro merged commit dab391d into v4-development Mar 6, 2025
1 check passed
@dscpinheiro dscpinheiro deleted the normj/remove-obsolete-endpoints-logic branch March 6, 2025 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants